linux的正则表达式

linux的正则表达式

 

linux的正则表达式是通过grep命令来实现的,举个最简单的例子的吧

$ ps -ef | grep 'python'

这个就是从所有的进程中找出含有python的那些

再来一个

$ netstat -nlp  | grep tcp | grep '33.+?'

这个表示找到那些tcp的监听端口是33开头的,比如是332,3306,3307这样的端口。

 

下面给出正则表达式的常用语法:

Regex operator Meaning
. Matches any single character.
? The preceding item is optional and will be matched, at most, once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
{N} The preceding item is matched exactly N times.
{N,} The preceding item is matched N or more times.
{N,M} The preceding item is matched at least N times, but not more than M times.
Represents the range if it's not first or last in a list or the ending point of a range in a list.
^ Matches the empty string at the beginning of a line; also represents the characters not in the range of a list.
$ Matches the empty string at the end of a line.
\b Matches the empty string at the edge of a word.
\B Matches the empty string provided it's not at the edge of a word.
\< Match the empty string at the beginning of word.
\> Match the empty string at the end of word.
 

 

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

留言

你的邮箱是保密的 必填的信息用*表示