Sed regex and substring negation

前端 未结 4 386
耶瑟儿~
耶瑟儿~ 2020-12-13 13:29

What is the correct syntax for finding a substring (a string which is preceded and followed by specific strings) which does not match a specific pattern?

4条回答
  •  长情又很酷
    2020-12-13 14:07

    There is no general negation operator in sed, IIRC because compilation of regexes with negation to DFAs takes exponential time. You can work around this with

    '/BEGIN_FOO_END/b; s/BEGIN_\(.*\)_END/(\1)/g'
    

    where /BEGIN_FOO_END/b means: if we find BEGIN_FOO_END, then branch (jump) to the end of the sed script.

提交回复
热议问题