in reply to 1 while s/// vs s///g
Merlyn-sama,
gregor42 bows humbly...
Do I grok your intention or am I to go back to meditation? .. :
1 while s/$string//;
Will 'collapse' the string:
"aaaaabbbbb"
From the middle... As each centre pair of "ab" are 'removed'(replaced will nil) the regex starts over completely and repeats the process. An extra 'a' on the left or an extra 'b' on the right of that string would be left over at the end of the operation.
INPUT: aaaaabbbbb OUTPUT:
Whereas:
s/$string//g;
Though looking at the string repeatedly, it does it's matching against only the first string and not the string subsequent to substitution. Hence, only the centre pair are removed and the rest left over. The added 'a' or 'b' on the left & right respectively, if added singly or doubly would not change how often the pattern is matched & would still be present with the rest of the characters in the string.
INPUT: aaaaabbbbb OUTPUT: aaaabbbb
Most thought provoking.... Thank you once again for sharing with those of us with lesser brain.
Was there deeper/more subtle meaning that I missed out on?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: 1 while s/// vs s///g
by merlyn (Sage) on May 23, 2001 at 23:54 UTC | |
|
Pumping Lemma
by John M. Dlugosz (Monsignor) on May 24, 2001 at 01:35 UTC |