我不知道正则表达式,需要找到表达式来隔离具有单词“comp”加上任何价格(数字)的字符串
任何想法?
249.00 | 259.00 | 279.00 | comp | 349.00 | //I need to return this as match
369.00 | 359.00 | 599.00 | //don't want to return this as match
299.00 | 499.00 | //don't want to return this as match
329.00 | //don't want to return this as match
comp | 269.00 | 269.00 | //I need to return this as match
179.00 | 239.00 | comp | //I need to return this as match
comp | //don't want to return this as match
89.00 | 89.00 | 89.00 | //no match
249.00 | //don't want to return this as match
comp | 249.00 | //I need to return this as matc
199.00 | comp | comp | //I need to return this as match
comp | comp | 99.00 | 99.00 | //I need to return this as match
comp | comp | comp | comp | comp | //I need to return this as match
答案 0 :(得分:1)
尝试
<强> (\bcomp\b.+([0-9]*[.]?[0-9]+))|(([0-9]*[.]?[0-9]+).+\bcomp\b)
强>
\bcomp\b
用于边界词comp
。
.+
代表一到多个字符。
[0-9]*[.]?[0-9]+
表示浮点数。
|
for或condition。 number | comp
或comp | number
答案 1 :(得分:0)
试试这个
/ \ d?+排版\ d?+ /克
它会将所有字符串“comp”与数字匹配。我觉得它适合你