我需要帮助将等于代码转换为匹配(正则表达式)。非常感谢。将java代码转换为一个正则表达式
//string composed of prefix and suffix - Can be spaced
//PREFIX - alfa-numeric, variable length, upper/lower case
//SUFFIX - numeric, variable length, can be spaced
String str="xpto 123 456 789";
String prefix_to_search="XPTO";
String digits_to_search="123456789";
//remove prefix (case insensitive)
str.substring(str.toUpperCase().startsWith(prefix_to_search) ? prefix_to_search.length() : 0).
//remove spaces
replace(" ","").
equals(digits_to_search));
给定一个字符串 “xpto 123 456 789”
MATCH
“123456789”
“123 456 789”
“1 2 3 4 5 6 7 8 9”
“XPTO 123 456 789”
“XPTO 1 2 3 4 5 6 7 8 9”
NOT MATCH
“12345678”
“1234567890”
“XPTO 12345678”
“XPTO 1234567890”
“XP 123 456 789”
“123 456 789 XPTO”
换句话说:
- 前缀必须是IGNORED(case INSENSITVE!)
- 数字必须匹配(空格必须忽略!)
请记住,你也可以在www.regexr.com上试试它 – ha9u63ar 2015-03-18 22:27:21
为什么?如果你的代码有效,你是否真的需要改变它? – 2015-03-18 22:31:45
它将应用于QUERY!我没有可用的所有字符串函数,但我可以使用“匹配”! – marcolopes 2015-03-18 22:36:16