By default (as in example X+) Java regex quantifiers are greedy , the regex engine starts out by matching as many characters it can. We can change this default behavior by appending another metacharacter e.g. X+?.
Read moreHow do I check if a case is insensitive in regex?
If you want only part of the regex to be case insensitive (as my original answer presumed), then you have two options:
Read more