You are here: PSPad forum > English discussion forum > Re: Regex help

Re: Regex help

#1 Regex help

Posted by: PSPadWood | Date: 2014-05-15 15:03 | IP: IP Logged

I'm very green when it comes to regex and now have a real need for it.

I'm trying filter out anything with a severity="0"
Sample
<ReportItem port="21" svc_name="ftp?" protocol="tcp" severity="0" pluginID="0" pluginName="" pluginFamily=""/>

I've tried various things i can't get anywhere

Options: Reply | Quote | Up ^


#2 Re: Regex help

Posted by: Andreas | Date: 2014-05-15 21:54 | IP: IP Logged

What do you mean with "anything"? Did you mean every xml tag that has the attribute ' severity="0"'?

Edited 1 time(s). Last edit at 2014-05-15 22:46 by Andreas.

Options: Reply | Quote | Up ^


#3 Re: Regex help

Posted by: myf | Date: 2014-05-19 11:19 | IP: IP Logged

If that XML file is reasonably small and well formated (one node pre line; you can use PSPad built-in function `HTML > Reformat HTML code` for that), you could filter lines you are interested in with PSPad even without regex: just search for ` severity="0"` (assuming no other things other than `ReportItem`s have this property nor this tring appears anywhere else) and click `Copy`: you'll get new file with lines containing such substring. This could serve you well, but is just quick'n'dirty approach.

If you haven't XML formatted nor want to format it, regex will be necessary; regex for `anything with severity="0"` in XML would look like
<[^ ]*( [^=]+="[^"]*")* severity="0"( [^=]+="[^"]*")*/>
assuming structure seen in your sample.

Alternatively, you can use your web browser's console to peek on the XML file (again, if it is not so huge): just open XML, press ctrl+shift+k (Firefox) or ctrl+shift+j (Chrome) to open console and input `$$('ReportItem[severity="0"]')`; you'll see matching nodes.

If the file is really big, I recommend dedicated application, Firstobject XML editor (Foxe), which stays fast, stable and powerful (but several GB large XML will be probably trimmed according your RAM; check statusbar). This app should be able to help filtering real XML tree but I'm not able to use it properly.

And if the file is really huge (GB), the last resort is command line utilities; last time I used gnuwin ports of grep and sed to clean several GB large XML to few MB.

Options: Reply | Quote | Up ^


#4 Re: Regex help

Posted by: Andreas | Date: 2014-05-19 12:24 | IP: IP Logged

If you are searching for the tag, regex can be easy
<.* severity="0".*?>
ps Did not work with newlines within a tag.

Edited 1 time(s). Last edit at 2014-05-19 12:51 by Andreas.

Options: Reply | Quote | Up ^


#5 Re: Regex help

Posted by: myf | Date: 2014-05-19 12:43 | IP: IP Logged

Yup, but with several tags on same line this matches all tags preceding the one of interest. (Yes, changing it to `<[^<]* severity="0".*?>` could fix that.)

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR