问题描述
我正在使用egrep查看perforce NAS中的脚本。
我正在试图找到我们使用RCP& RSH ....我遇到的问题是1)我在REGEX吸吮; 2)我正在拾取垃圾我不感兴趣,例如,如果一个文件有strcpy这个词,它会在RHS上选择RCP或所有权..
显然我对这些不感兴趣,但我不想根据所有权或strcpy排除行......因为它们可能会一起使用......并且它不是完整的列表。 p>
这是我的正则表达式
'ftp | rcp | rsh'
如何修改这些命中FTP,但不是SFTP ... rcp,但没有strcpy,rsh,但没有所有权.....等等。
所以我想匹配的东西。
ftp
`ftp`
/ ftp /
PUNCTFTPPUNCT
有几个元字符:
$ b
\ b
字界
\<
字开头
\>
字尾
,一个可能的正则表达式是: \<(ftp | rcp | rsh)\>
I am using egrep to look through scripts in our perforce NAS.
i am trying to find where we use RCP & RSH....The problem i have is that 1) I suck at REGEX; 2) i am picking up junk I am not interested in. For example if a file has the word strcpy..it picks up on RCP..or ownership..hits on RSH.
Obviously i am not interested in those, but I don't want to exclude lines based on the words ownership or strcpy...because they may be used in conjunction...and its not a complete list.
Here is my regex
'ftp|rcp|rsh'
How can mod these to hit on FTP, but not SFTP...rcp but no strcpy, rsh but not ownership.....etc.?
So Things I would want to match.
ftp
`ftp`
/ftp/
"PUNCT"FTP"PUNCT"
There are several metacharacters:
\b
word boundary\<
word start\>
word end
So, one possible regex is: \<(ftp|rcp|rsh)\>
这篇关于正则表达式只能使用egrep捕获整个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!