Sign in to follow this  
Followers 0
Ventura

String regex remove text inside data

3 posts in this topic

well I don't a thing about regex other than just replacing plain text /: 

So I have this text 

<data>
<us1></us1>
<eu1></eu1>
<rt2></rt2>
<le2></le2>
</data>

I want to remove all those text inside the data

so I get output like this

<data>
</data>

SO far after searching the forum for hours I have come up with this 

$sText = "<data><us1><eu1><rt2><le2></data>"

Local $sStart = "(\<data>)"
Local $sEnd = "(\</data>)"
Local $sReplace = ""& @CRLF &""

$Text = StringRegExpReplace($sText, "(?i)" & $sStart & "([^\<]*)" & $sEnd , "$1" & $sReplace & "$3")

MsgBox(0, "", $Text)

It works only with text inside the data but not after putting several "<>" ..

Share this post


Link to post
Share on other sites



ventura,

?

$sText = '<data1><us1><eu1><rt2><le2></data1>' & @CRLF & '<data2><us2><eu2><rt22><le22></data2>' & @LF & '<data3><us3><eu3><rt23><le23></data3>'

$Text = StringRegExpReplace($sText, '(?i)(<data.>)(.*?)(</data.>)', '$1$3')

MsgBox(0, "", $Text)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

(?s) option suggested  :)

sText = '<data><us1><eu1><rt2><le2></data>' & @CRLF & '<data><us2><eu2><rt22><le22></data>' & @LF & '<data><us3><eu3><rt23><le23></data>'

$Text = StringRegExpReplace($sText, '(?is)(?<=<data>)(.*?)(?=</data>)', "")

MsgBox(0, "", $Text)

 

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
Sign in to follow this  
Followers 0