in reply to Re: This regexp made simpler
in thread This regexp made simpler
I wonder why it is necessary to match something like 'AZZ' and yet grab an undefined value from it.Good point. This made me rethink my problem. In my case, the grabbed part is not really kept in a variable (I wrote it in that way in the hope to make the whole posting simpler), but within a substituion (to be precise, an insertion): I need to change a text AXZ into AXIZ, where the X is optional. In otherwords, I have to insert I in front of the Z, so in the substitution I use
, and if I know that $1 is always defined, I don't have to care about interpolating an undefined value. In hindsight, I now see that I should better have writtens/..../A$1IZ/
. :-(s/^(A(?:\s.*?)?(Z))/$1I$2/
|
|---|