Gary’s got the right idea, but this code happens to be Objective-C code, so it’s not actually using either of these functions. However, I am using the case-insensitive option when evaluating the regular expression, so
[A-Z] will match both upper and lower case. I should have mentioned this. Also, in this case
regexarray( isn’t what I would use if this was Panorama code, I’d be using the
regexmatch operator in this application, like this:
functionname regexmatch "^[A-Z][A-Z0-9_.Ω]*[(]*$"
For educational purposes, let me break down the components of this regular expression. Here’s the expression without the quotes.
It starts with
This means that the match must start with the first character. Otherwise you could have all sorts of junk at the beginning.
This means the first character of the match must be a letter. Since I’m using a case insensitive regex either upper or lower case will work. If I was using the case sensitive options (which Panorama calls exact) then I could still match upper and lower case by using
[A-Za-z] instead. Gary suggested using
[A-z] which would work, but would also match a few additional characters: `[, , ], ^, _, and ``.
This means the next character can be a letter, number, underscore, period or omega. The
* on the end means that this match can occur 0 or more times. So it’s ok if there are no additional characters, or one, or twenty.
This means that can be a
( on the end, but it is optional (0 or more times). So this means you could define a function name of
abc(((. As it turns out, Panorama removes all of the ( characters, so it doesn’t matter if you add extra ones, the name would still be
This means the last character of the pattern must match the last character of the matched text. In other words, there can’t be any extra text on the end. Because of the $, names like this won’t work.
That’s it! Writing explicit code to test if text matched all of these criteria would be a lot more difficult.