正则表达式匹配任何逗号分隔值

时间:2012-11-12 21:49:04

标签: regex csv

我正在尝试将正则表达式发送到与逗号分隔值匹配的mongodb。

例如'aaa'应匹配:

aaa, ancient, pattern, discipleship, faithful, followers         matches
lowers,aaa, gospel, righteousness, strengthen, family       matches
lowers, aaa , gospel, righteousness, strengthen, family     matches
lowers, goaaaspel, righteousness, strengthen, family        no match
lowers, aaaspel, righteousness, strengthen, family          no match
lowers, gospel aaa truth, righteousness, strengthen         no match
lowers, gospel aaa, righteousness, strengthen, family       no match
lowers, gospel, righteousness, strengthen, family aaa        no match
lowers, gospel, righteousness, strengthen, family, aaa       matches

感谢。

1 个答案:

答案 0 :(得分:1)

这似乎适用于附加的例子:

(?<=,|^)(\s*)aaa(?=\s*,|\s*$)

它基本上意味着'aaa'在它之前有行开头或逗号,行尾或逗号之后。 它会捕获前导空格,但您可以通过分组来解决这个问题。