But that doesn't match 'AZ', which the OP seems to require, and also doesn't match 'A Z' (single space between first and final characters), which also seems to be required.
| [reply] |
A simple variation fixes that:
/A( [^Z]*)?Z/
It surprises me how many monks in this thread seem to think that expressing the "no Z between ..." condition with .*? is a good idea.
| [reply] [d/l] [select] |
Indeed. That was the main point I was going to contribute, but you've beat me to it.
The OP even specifically says he wants to match "any number of characters not containing Z", which is properly written [^Z]*. .*?Z means "the shortest available sequence of any character at all (except, usually, newlines), followed by a Z", which is not quite the same thing.
| [reply] [d/l] [select] |
>perl -wMstrict -le
"'AZ' =~ /A( [^Z]*)?Z/;
print qq{'$1'};
"
Use of uninitialized value $1 in concatenation (.) or string at ...
''
'Elegance', admittedly protean, would yet seem to require avoiding this extra step.
| [reply] [d/l] [select] |
| [reply] [d/l] |
printf( "\n$_: " ),
m[A( [^Z]*|)Z] and print "'$1'"
for 'AZ', 'A SOMETHING Z', 'ASOMETHINGZ', 'A Z', 'A Z';;
AZ: ''
A SOMETHING Z: ' SOMETHING '
ASOMETHINGZ:
A Z: ' '
A Z: ' '
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |