Iczer Posted January 4, 2021 Share Posted January 4, 2021 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? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 5, 2021 Share Posted January 5, 2021 @Iczer Do you want to remove those attributes from the input string? If so, this pattern should do the trick: '(?si)(attr[257]=[\x22\x27\x60][^\x22\x27\x60]++[\x22\x27\x60])' Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted January 5, 2021 Share Posted January 5, 2021 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now