开发者

use grep to capture regex

开发者 https://www.devze.com 2023-03-12 16:13 出处:网络
I have trouble capturing text like the following in input: \"xy$\" I did grep -eo \'([a-zA-Z]+)$\' grep -eo \'([a-zA-Z]+)\\$\'

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

精彩评论

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