|P is for Practical|
RegExp: pos management in global substitutionby OlegG (Monk)
|on Sep 03, 2011 at 11:02 UTC||Need Help??|
OlegG has asked for the
wisdom of the Perl Monks concerning the following question:
I have such text:
And want to get this:
In other words I want to remove all parameters with names different from "param_x" and "param_y" in all tags with name "name_a".
Can this be done with s/// operator without e modifier in one approach?
That's what I think about it:
In this way we will remove only first undesirable parameter.
But if we could say to regexp engine:
1. After success substitution return to the position where substitution started and try to substitute again
2. If ok, go to step 1. If nothing matched in this position move along the string as usual and when matched and substituted go to step 1.
In this way work will be done correctly.
Please tell me, is it possible with Perl regexp engine? Or can yo provide me other solution?