How to escape a previously unknown string in regular expression?

前端 未结 3 1558
栀梦
栀梦 2020-12-16 03:47

I need to egrep a string that isn\'t known before runtime and that I\'ll get via shell variable (shell is bash, if that matters). Problem is, that string will c

3条回答
  •  天涯浪人
    2020-12-16 04:45

    Use the -F flag to make the PATTERN a fixed literal string

    $ var="(.*+[a-z]){3}"
    $ echo 'foo bar (.*+[a-z]){3} baz' | grep -F "$var" -o
    (.*+[a-z]){3}
    

提交回复
热议问题