regexp匹配字符串与word1而不是word2 [英] regexp match string with word1 and not word2
问题描述
您好,
i再次出现regexp问题:-P
我需要匹配包含一个单词但不包含的所有行
另一个。
喜欢做grep one | grep -v two:"
字符串的语法是:
(任何可打印的字符)二:(任何可打印的字符)一个(任何可打印的字符)
例如:
4月30日00:00:09 v890neg0二:[ID 702911 daemon.one]调查结果:
blablabla
我尝试过:
.. * [^ t] [^ w] [^ o]。* one。*
但是没有工作,字符串始终匹配,在其他尝试中使用较少逻辑的
我总是得到一些不同的匹配:-(
PS:我没有更多的re.search,所以我只需要一个正则表达式
Flyzone写道:
你好,
i再次出现regexp问题: -P
我需要匹配包含一个单词但不包含
另一个单词的所有行。
喜欢做grep one | grep -v two:"
字符串的语法是:
(任何可打印的字符)二:(任何可打印的字符)一个(任何可打印的字符)
例如:
4月30日00:00:09 v890neg0二:[ID 702911 daemon.one]调查结果:
blablabla
>
我尝试过:
。* [^ t] [^ w] [^ o]。* one。*
但是没有用,字符串总是匹配,在其他尝试中
使用较少的逻辑我总是得到一些不同的匹配:-(
PS:我不能有更多的re.search,所以我只需要一个regexp
PS:建议作业,但这不能做作业,因为python
正则表达式不会这样做,所以你的老师得到一个F如果它家庭作业。你需要一个可变长度的负面后瞻断言 - 而不是在python正则表达式中可能是
。你将不得不使用别的东西 - 或者
你不懂家庭作业的问题。
詹姆斯
Flyzone写道:
PS:我没有更多的re.search,所以[clip]
这让我想起了伟大的研究员罗伊加西亚的一句话:
如果它第一次工作,他们只会称之为搜索。 br />
James
Flyzone写道:
你好,
i再次出现regexp问题:-P
我需要匹配包含一个单词但不包含的所有行
另一个。
赞要做grep one | grep -v two:
你不需要正则表达式:;
如果''one''排队和''两个:''不排队:
......做点什么...
STeVe
Hello,
i have again problem with regexp :-P
I need to match all lines that contain one word but not contain
another.
Like to do "grep one | grep -v two:"
The syntax of the string is:
(any printable char)two:(any printable char)one(any printable char)
Example:
Apr 30 00:00:09 v890neg0 two: [ID 702911 daemon.one] findings:
blablabla
I tried with:
..*[^t][^w][^o].*one.*
but is not working, the string is always match and in other tries
using "less logic" i get always some different match :-(
P.S: i can''t have more re.search, so i just need ONE regexp
Flyzone wrote:Hello,
i have again problem with regexp :-P
I need to match all lines that contain one word but not contain
another.
Like to do "grep one | grep -v two:"
The syntax of the string is:
(any printable char)two:(any printable char)one(any printable char)
Example:
Apr 30 00:00:09 v890neg0 two: [ID 702911 daemon.one] findings:
blablabla
I tried with:
.*[^t][^w][^o].*one.*
but is not working, the string is always match and in other tries
using "less logic" i get always some different match :-(
P.S: i can''t have more re.search, so i just need ONE regexp
The P.S: suggests homework, but this can''t be homework because python
regex won''t do this, so your teacher gets an F if its homework. You
require a negative look-behind assertion of variable length--not
possible in python regex. You will have to use something else--or maybe
you don''t understand the homework problem.
James
Flyzone wrote:P.S: i can''t have more re.search, so [clip]
This reminds me of a quote by the Great Researcher Roy Garcia:
If it worked the first time, they''d just call it "search".
James
Flyzone wrote:Hello,
i have again problem with regexp :-P
I need to match all lines that contain one word but not contain
another.
Like to do "grep one | grep -v two:"You don''t need a regexp:;
if ''one'' in line and ''two:'' not in line:
... do something...
STeVe
这篇关于regexp匹配字符串与word1而不是word2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!