Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

According to grep --help and man grep, we can use the -P option in order to interpret the pattern as a Perl regular expression (PCRE, to be precise), instead of the default POSIX basic regular expressions (BRE).

In Perl language, various Modifiers can be added to the expression, in order to adjust the pattern interpretation (in the syntax of /pattern/modifiers).

So, how can someone add modifiers to the grep's Perl regular expression? I tried some variations like grep -P "/^got.it$/ms" [FILE] but the search results were wrong.

However, about the PCRE interpretation, the manual points out that:

This is highly experimental and grep -P may warn of unimplemented features.

Is it possible that the grep tool does not support modifiers at all?

By the way, I noticed that one can perform case-insensitive pattern matching by using the -i option, which is an example of a modifier.

share|improve this question
    
Crossposted: unix.stackexchange.com/questions/110875/… –  goldilocks Jan 25 at 14:35
add comment

1 Answer

up vote 1 down vote accepted

For the modifiers imsxadlup you can use the (?X) for as described in Extended Patterns:

$ echo FOO | grep -P '(?i)foo'
FOO
share|improve this answer
    
Amazing, thanks! –  Reflection Jan 25 at 14:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.