Herr Bischoff


RegEx Escape String in Shell

Searched for an easy way to escape a string for regular expression matching on the command line, didn’t find anything useful, created my own:

sed -E 's/([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\-\#])/\\1/'

Wrap it in a function to easily call it whenever you need.