简体   繁体   中英

regular expression for log

I have a log file like this:

some strings...
<FX>
another strings...
<FX s='asdf' asd="ascvas">
<TEG1>
  <TEG2>
  </TEG2>
</TEG1>
</FX>
some strings...
</FX>
some strings...
<FX>
             <?xml version="1.0" encoding="utf-16" standalone="yes"?>    

<FX>
<CLR>
</CLR>
</FX>
end of file
</FX>

I need to write on vbscript regular expression to parse it and get this results:

<FX s='asdf' asd="ascvas">
    <TEG1>
      <TEG2>
      </TEG2>
    </TEG1>
</FX>

And

<?xml version="1.0" encoding="utf-16" standalone="yes"?>    
<FX>
    <CLR>
    </CLR>
</FX>

I have already wrote this expression:

(<\?xml[^>]*>[\s\S]*)*<\s*FX[^>]*>((?!<\s*FX[^>]*>)[\s\S])*<\s*/\s*FX\s*>

But it doesn't work correct with tag /FX. You could view rezult here: http://regexr.com?341ps

Thanks in advance.

这样更改:

^\<\?xml[^>]*>[\s\S]*<\s*FX[^>]*>((?!<\s*FX[^>]*>)[\s\S])*<\s*/\s*FX\s*>
/(<[^\s]+\s+\w=[^>]+>[^/]+\/[^/]+/[^/]+/[^>]+>)|(<\?xml[^/]+/[^/]+/[^>]+>)/m
# http://regexr.com?386si


/(<[^\s]+\s+\w=[^>]+>[^\/]+\/[^\/]+\/[^\/]+\/[^>]+>)|(<\?xml[^\/]+\/[^\/]+\/[^>]+>)/m
# (escaped forward slash)
# http://rubular.com/r/SwI2vz6ctk

http://regexr.com?386si

http://rubular.com/r/SwI2vz6ctk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM