Reputation:
I know I can add case insensitivity by adding (?i). However I have this regex:
@badbots header_regexp User-Agent "(AhrefsBot|copyright|check)"
I want case insensitivity for all values by insert (?i) only once. How to do that?
I do not want to insert (?i) in each value like so:
@badbots header_regexp User-Agent "((?i)AhrefsBot|(?i)copyright|(?i)check)"
Upvotes: 0
Views: 123
Reputation: 627082
There is no need to repeat the inline modifier. You can use
@badbots header_regexp User-Agent "(?i)(AhrefsBot|copyright|check)"
@badbots header_regexp User-Agent "(?i)AhrefsBot|copyright|check"
The case insensitivity mode is enforced from the very start of the pattern and all the patterns that are located to the right of the inline modifier are acting as case insensitive.
Note you do not even need a capturing group. However, you may use an inline modifier group, where case insensitivity affects only the patterns in the group:
@badbots header_regexp User-Agent "(?i:AhrefsBot|copyright|check)"
Upvotes: 1