Jump to content
Iczer

StringRegexpReplace with pattern position reset?

Recommended Posts

I need to clean up text with xml tags from some attributes. Problem is - the random order those attributes placed. It would be simple if use 1 regexp for 1 attribute clearance, but it's not effective. So target is one complex pattern:

to clear attributes attr7,attr2 and attr5 from :

"<xmlTag attr0="aaa" attr1="bbb" attr2="ccc" attr3="ddd" attr4="eee" attr5="fff" attr6="ggg" attr7="hhh" attr7="iii" />"

Not working:

$sPreFilter = StringRegExpReplace(ClipGet(),"(?si)(\A.+?<xmlTag[^>]+?)(\attr7=[\x22\x27\x60][^\x22\x27\x60]++[\x22\x27\x60]|attr2=[\x22\x27\x60][^\x22\x27\x60]++[\x22\x27\x60]|attr5=[\x22\x27\x60][^\x22\x27\x60]++[\x22\x27\x60])([^>]+?>.+\z)","$1 $3")

Is it possible use (and how) reset start of match "\K" for it?

Share this post


Link to post
Share on other sites

This could also be done using backreferences, subpattern calls and group reset

$s = '<xmlTag attr0="aaa" attr1="bbb" attr2="ccc" attr3="ddd" attr4="eee" attr5="fff" attr6="ggg" attr7="hhh" attr7="iii" />' 

$r = StringRegExpReplace($s,'(?si)(?|attr2=(([\x22\x27\x60])[^\x22\x27\x60]+\2)|attr5=(?1)|attr7=(?1))',"")

Msgbox(0,"", $r)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...