Hi all
I have such text:
{name_b param_v="wh"}
{name_a param_x="abc" param_a="fsd" param_y="def"}
{name_z param_sd="zka" param_s="df"}
{name_a param_y="wtf" param_z="kro" param_c="ptz" param_ch="www"}
And want to get this:
{name_b param_v="wh"}
{name_a param_x="abc" param_y="def"}
{name_z param_sd="zka" param_s="df"}
{name_a param_y="wtf"}
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:
s/(\{name_a[^}]+?)\w+(?<!param_x|param_y)="[^"]+"/$1/g;
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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.