![]() ![]() It may look weired but it is just a concatenation of 'O', \' and 'Reilly'. ![]() Let me simplify the string as an example: O'ReillyĪs you know, a backslash does not work to escape the single quote within single quotes: str='O\'Reilly' # wrong Quotes if the string includes single quote(s) inside. The only thing you need to know is how to enclose a string with single ) are not supported by most other engines, which means that the previous sequence would match on these characters: \, x, 7, 0-\, x, 7, f). Escaped hexadecimal sequences inside character class expressions (ie. Note that your regex require a Perl-compliant regex engine (aka. From that point, you can directly provide that variable to grep or sed.įor example: function regex() | grep -P $( regex ) For example, you can write something like this: by wrapping that Here Doc into a function, you can easily grab this to a variable. ![]() Let's combine two useful Bash features to get there.įirst, you can completely avoid the need to escape a string using a Here Doc with quoted delimiter (ie. I assume that the regular expression needs to be escaped, but i didn't find any good tool that can do it for me.Īny idea how can i let grep use this regular expression in bash? What is the best way to convert a regular expression to a string which can be accepted by grep/sed in bash?įor example, given the following regular expression does not like it (and thus this regular expression cannot be used in grep) $ echo syntax error near unexpected token `(' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |