in reply to regex capture case

Your match statement: /($regex)/i; means: match any of these: Aa,aA,aa,AA followed by zero or more characters. The /i means case insensitive. Also the "Aa.*" does not "anchor" the expression to the front, "Baababoo" would match also. Anchor the regex with the ^ character. "^Aa.*".

But it appears that to make this work, you should just delete the "i". I am assuming that you misspoke ($regex) should be ($someRegex). Of course it is possible that I've misunderstood your intent.

Aa.* means 'A' then 'a' then anything which by definition "anything" is case insensitive.