Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi-line xml regex in sublime

I have a large logfile (+100 000 lines) in XML like so:

<container>
   <request:getApples xml="...">
     ...
   </request:getApples>
   <request:getOranges xml="...">
     ...
   </request:getOranges>
</container>
...

I want to extract the :getXXXX part to

getApples
getOranges

by doing a regex find & replace in Sublime Text 2.

Something like

Find:      [^(request:)]*(.*) xml
Replace:   $1\n

Any regex masters that can assist?

like image 328
Cotten Avatar asked Nov 30 '25 21:11

Cotten


1 Answers

Correcting mart1n's answer and actually using ST2 and your sample input, I came up with the following:

First, CtrlA to select all. Then, CtrlH,

Search: .*?(get\w+) .*
Replace: $1

Replace All

Then,

Search: ^[^get].*$
Replace: nothing

Replace All

Finally,

Search: ^\n
Replace: nothing

Replace All

And you're left with:

getApples
getOranges
like image 153
MattDMo Avatar answered Dec 04 '25 12:12

MattDMo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!