I would like to match the following:
Match A, optionally followed by any number of characters
not containing Z, followed by Z, with the additional restriction that *if* there are characters between A and Z,
the character immediately following A must be a space.
In case of a match, grab what is between A and Z.
Examples for matching strings:
Example for non-matching strings:
The obvious solution, as far I can see, goes like this:
I don't like the repeating of Z in this pattern. Any suggestion for a more elegant way to do this?
I just came up with this:
This seems to fulfil the condition. Still, if you have nice alternatives, I would like to see them. Plus, is there a way to write the regexp so that $1 is always defined in case of a match? Right now it is undef if the string to match is AZ (that's why I have to use the // operator).
Ronald Fischer <email@example.com>