Sea*_*ell 4 python regex data-mining
我试图排除在“狗”一词之前有“所有者”一词的记录
这是当前的正则表达式:
\b(?<!owner\s)\w+\sdog\b
Run Code Online (Sandbox Code Playgroud)
这适用于单个未知单词(排除“主人有狗”,但包括“主人有狗”)),但是,我无法捕获多个单词,这些单词在“主人”和“主人”之间的所有单词中保留其负面外观。 “狗”。
非常感谢
您可以使用以下正则表达式来验证字符串是否包含单词“dog”且前面没有单词“owner”。
\n^(?:(?!\\bowner\\b).)*\\bdog\\b\nRun Code Online (Sandbox Code Playgroud)\n启动你的引擎! < \xc2\xaf\\ (\xe3\x83\x84) /\xc2\xaf > Python 代码
\nPython 的正则表达式引擎执行以下操作。
\n^ : anchor match to beginning of string\n(?: : begin a non-capture group\n (?!\\bowner\\b) : use a negative lookahead to assert that the current\n position in the string is not followed by "owner"\n . : match a character\n) : end non-capture group\n* : execute non-capture group 0+ times\n\\bdog\\b : match \'dog\' surrounded by word boundaries\nRun Code Online (Sandbox Code Playgroud)\n匹配不以非法单词开头的单个字符序列的技术称为“Tempered Greedy Token Solution”。
\n| 归档时间: |
|
| 查看次数: |
352 次 |
| 最近记录: |