1

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

例如 '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

谢谢。

4

1 回答 1

1

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

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

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

于 2012-11-12T22:03:55.310 回答