java – Are captures in case-insensitive regex expressions always case-preserving?

Given a regex expression which has been made case-insensitive using the i flag or (?i) and which contains capture groups, such as the following example:

(?i)username: (?\S) role: (?\S)

are the captures extracted from it guaranteed to be in the case they were in the original string?

That is to say, if I were to apply the above regex to the example string

username: coolGuy99 role: ADMIN

am I going to get user=coolGuy99 and role=ADMIN in all circumstances or is it possible for the regex engine to return values such as coolguy99 or COOLGUY99 for user and admin or Admin for role?

A brief test on regex101 shows that at least its engine does preserve case in matches, but I’d like confirmation that there isn’t some edge case for which this isn’t true before relying on it.

I’m using the java dialect for my project, but to make the question more generally useful I’d appreciate answers that are valid for all engines/dialects or, if the answer differs between them, acknowledge which ones do and which ones don’t preserve case.

Read more here: Source link