anon
anon

Reputation:

How to use Regex in Windows Tools to find something in a XML file?

I have a big XML file (~20 MB) that contains among others such lines:

<BUR value="0.01" />

Now I want to find all lines where value is greater than 0.33. How can I do this in Windows?

Upvotes: 0

Views: 166

Answers (2)

Tim Pietzcker
Tim Pietzcker

Reputation: 336428

Hm. Matching number ranges isn't regexes' strong suit.

A regex that would work on arbitrary precision floats (except for exponential notation) could look like this:

<BUR value="0*(?:[1-9]\d*\.\d*|0\.[4-9]\d*|0\.3[4-9]\d*|0\.33(?!0+")\d+)" />

In PowerShell, which comes with Windows Vista, you could iterate over all lines that contain a matching string like this:

$regex = [regex] '(?m)^.*<BUR value="0*(?:[1-9]\d*\.\d*|0\.[4-9]\d*|0\.3[4-9]\d*|0\.33(?!0+")\d+)" />.*$'
$matchdetails = $regex.Match($subject)
while ($matchdetails.Success) {
    # matched text: $matchdetails.Value
    $matchdetails = $matchdetails.NextMatch()
} 

Upvotes: 1

Steven D. Majewski
Steven D. Majewski

Reputation: 2167

I don't know a Windows specific answer, but you can do this with Perl's XML:Xpath library better and easier than using regex:

$ xpath blurtst.xml  '//BLUR[@value > "0.33"]'
Found 4 nodes:
-- NODE --
<BLUR value="0.40" />-- NODE --
<BLUR value="0.50" />-- NODE --
<BLUR value="0.34" />-- NODE --
<BLUR value="0.35" />

Upvotes: 1

Related Questions