I have a regex where part of the regex should be case insensitive.
Example:
/Guest post by ([A-Z][a-z]+\s[A-Z][a-z]+)/
"Guest post by" should be case insensitive, but the 2nd half obviously needs to be case sensitive as it's looking for a first name + last name, with the first letter capitalized in each.
So if I do
/Guest post by ([A-Z][a-z]+\s[A-Z][a-z]+)/i
it won't work because now it'll match things such as "Guest post by small dog", which I don't want.
However, it needs to match with "GUEST POST BY Brian Williams".
Use the case-insensitive modifier pattern:
(?i:)
In your case:
(?i:Guest post by )([A-Z][a-z]+\s[A-Z][a-z]+)
Working example: http://regex101.com/r/pW1gV9
Alternatively (thanks @robertodecumex!) you can use a modifier range, which is handy if you want to exclude the result from capture.
(?i)Guest post by(?-i) ([A-Z][a-z]+\s[A-Z][a-z]+)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With