开发者

use grep to capture regex

I have trouble capturing text like the following in input:

"xy$"

I did

grep -eo '([a-zA-Z]+)$'
grep -eo '([a-zA-Z]+)\$'
grep -eo '([a-zA-Z]+)\\$'

here the $ represents the literal $ no开发者_JAVA技巧t end of line.

what's wrong?


You need to escape $, so it becomes a literal

([a-zA-Z]+)\$


Try to escape the $. grep -eo '([a-ZA-Z+)\$


You need to turn on extended regexes with the -E option:

grep -E '([a-ZA-Z]+)\$'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜