The Basic Set—GNU grep's Regular Expression Metacharacters


Metacharacter

Function

Example

What It Matches

^

Beginning-of-line anchor

^love

Matches all lines beginning with love.

$

End-of-line anchor

love$

Matches all lines ending with love.

.

Matches one character

l..e

Matches lines containing an l, followed by two characters, followed by an e.

*

Matches zero or more characters

*love

Matches lines with zero or more spaces, of the preceding characters followed by the pattern love.

[ ]

Matches one character in the set

[Ll]ove

Matches lines containing love or Love.

[^]

Matches one character not in the set

[^A–K]ove

Matches lines not containing A through K followed by ove.

\<[a]

Beginning-of-word anchor

\<love

Matches lines containing a word that begins with love.

\>

End-of-word anchor

love\>

Matches lines containing a word that ends with love.

\(..\)[b]

Tags matched characters

\(love\)able

Tags marked portion in a register to be remembered later as number 1. To reference later, use \1 to repeat the pattern. May use up to nine tags, starting with the first tag at the leftmost part of the pattern. For example, the pattern love is saved in register 1 to be referenced later as \1.

x\{m\}

x\{m,\}

x\{m,n\}[c]

Repetition of character x:

m times,

at least m times, or

between m and n times

o\{5\}

o\{5,\}

o\{5,10\}

Matches if line has 5 occurrences of o,

at least 5 occurrences of o, or

between 5 and 10 occurrences of o.

\w

Alphanumeric word character; [a-zA-Z0-9_]

l\w*e

Matches an l followed by zero more word characters, and an e.

\W

Nonalphanumeric word character; [^a-zA-Z0-9_]

love\W+

Matches love followed by one or more nonword characters (., ?, etc.).

\b

Word boundary

\blove\b

Matches only the word love.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值