如何使用jsl测试字符串是否只包含A~Z和0~9?<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />如何使用jsl测试字符串是否只包含A~Z和0~9?
我的数据应仅包含 A~Z 和 0~9,但当 1 或几位翻转时,则没有可打印的字符。
提前谢谢了!
Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?谢谢! regex101 有助于理解您共享的代码。
Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?如果您只需要知道找到或未找到,则使用一个正则表达式相当简单,如果您还需要匹配项,则需要在替换找到的匹配项时循环遍历字符串。 另外,如果您需要测试您的正则表达式,我建议正则表达式101
Names Default To Here(1);
original_txt1 = " today I m at FL12, tomorrow I will be at FL 103";
original_txt2 = " today I m at FLb12, tomorrow I will be at FL a123";
// if you only need to know if there is a match combine regex with !IsMissing()
found1 = !Is Missing(Regex(original_txt1, "FL\s?\d+"));
found2 = !Is Missing(Regex(original_txt2, "FL\s?\d+"));
show(found1, found2);
// if you also need the matches loop over the string
matches = {};
While(!Is Missing(rgx_match = Regex(original_txt1, "FL\s?\d+")),
Insert Into(matches, rgx_match);
Substitute Into(original_txt1, rgx_match, "");
);
show(matches);
据我所知,JMP 无法使用 Regex Match() 执行“全局”正则表达式搜索,我已为其创建了愿望清单项向 Regex Match() 添加标志以查找所有不重叠的模式出现)。 你很可能会使用JMP 自己的模式匹配做诸如查找多个匹配项之类的任务,但我没有费心去学习它。 这是关于这个的好帖子模式匹配
Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?你好
我想知道正则表达式是否可以在文本中使用?
Text =“今天我在 FL12,明天我将在 FL102”
我有几行文本,我想找出每行是否包含 FL + 任意数字,那么是,或者打印 FL+数字。 在本例中,它将是 FL12 和 FL103。
如果没有正则表达式,你能建议其他功能吗?
Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?谢谢@pmroz以获得说明。 对于一些特别脏的数据非常有用。
如果其他人需要一个方便的示例,请尝试以下操作:
If(
Regex( :"2nd"n, "^[A-Z]+$" ) == :"2nd"n, "Uppercase",
Regex( :"2nd"n, "^[a-z]+$" ) == :"2nd"n, "Lowercase",
Regex( :"2nd"n, "^[0-9]+$" ) == :"2nd"n, "Numbers",
Regex( :"2nd"n, "^[A-Z0-9]+$" ) == :"2nd"n, "Uppercase and numbers",
Regex( :"2nd"n, "^[a-z0-9]+$" ) == :"2nd"n, "lowercase and numbers",
Regex( :"2nd"n, "^[A-Za-z]+$" ) == :"2nd"n, "No numbers",
Regex( :"2nd"n, "^[A-Za-z0-9]+$" ) == :"2nd"n, "All characters",
Regex( :"2nd"n, "^[A-Za-z0-9]+$" ) != :"2nd"n,
"includes non alphanumeric characters"
)

Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?^ 表示字符串的开头,+ 表示匹配至少一个字符,$ 表示字符串的结尾。
要返回 1 或 0,只需将 Yes 更改为 1,将 No 更改为 0:
如果(正则表达式( :姓名( “第二” ) , “^[a-zA-Z0-9]+$” ) == :姓名( “第二” ) , 1 , 0 )
顺便说一句,有很多网站解释正则表达式。
Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?感谢您的回复,PMroz。
^ 和 +$ 是做什么用的?
我怎样才能让它返回1或0,以便我可以将它与其他比较算法一起使用?
Re: 如何使用jsl测试字符串是否只包含A~Z和0~9?您可以使用正则表达式来检查这一点。创建一个包含以下公式的新列:
如果(正则表达式( :姓名( “第二” ) , “^[a-zA-Z0-9]+$” ) == :姓名( “第二” ) , “是的” , “不” )
如果新列是纯字母数字,则其值为“是”,否则为“否”。