Your regular expression is incorrect. /[^AZ]*/ means "combine zero or more characters that are not between A and Z anywhere on the line." The string ABC has null characters that are not between A and Z , so it matches the regular expression.
Change your regular expression to /^[^AZ]+$/ . This means that βmatches one or more characters that are not between A and Z , and make sure that each character between the beginning and end of the line is not between A and Z β. Then the string ABC will not match, and then you can check matches[0].size or whatever, like the answer of sepp2k.
source share