> s/(i)(\d\d)(o)/1$20/;
You don't need to capture the "i" or "o" s/i(\d+)o/1${1}0/ If there were more i or o's, 2 subs s/i/1/g s/o/0/g The "g" globally replacing all the matches. There's probably a tricky way to do that in one but. > Since you are capturing 3 groups: s/(i)([0-9]{2})(o)/$1$2$3/; Er, bit of a no-op there ;-> s/(i)([0-9]{2})(o)/1${2}0/; a Andy Bach (608) 658-1890 Not at my desk On Jan 3, 2013, at 2:22 AM, "Dr.Ruud" <rvtol+use...@isolution.nl> wrote: > On 2013-01-02 15:34, Hamann, T.D. wrote: > >> [...] given a string: >> >> i99o >> >> where I want to replace the 'i' by a '1' and the 'o' by a '0' (zero), the >> following regex fails: >> >> s/(i)(\d\d)(o)/1$20/; > > Since you are capturing 3 groups: > > s/(i)([0-9]{2})(o)/$1$2$3/; > > >> >> for the obvious reason that perl looks for a pattern match at bracket set >> #20, which doesn't exist. >> >> I can fix this by inserting a space in front of the zero, like this: >> >> s/(i)(\d\d)(o)/1$2 0/; >> >> and then using a second regular expression to remove the space, but that >> somehow seems silly. Surely there is a quicker way to do this? >> >> Regards, >> Thomas Hamann > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > >