LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

match regular expression and add to array

hello. Im having some issues with this.

I have a very long multi line string with a lot of numbers in it. The string is from a HTML so contains a lot of junk as well. 

I want to match the expression <td class="s0" dir="ltr">[0-9].[0-9]</td> 

[0-9].[0-9] being either a 2 digit or 3 digit number with 2 decimal places (100.11 or 99.88) and then take these numbers and add them to an array.

 

i tried matching the expression <td class="s0" dir="ltr">[0-9].[0-9]</td> but tht just returns <td class="s0" dir="ltr"> </td> from the whole match node.

 

Screenshot_18.png

am i using this right and if so why is it not pulling up the numbers.

0 Kudos
Message 1 of 7
(4,424 Views)

Hi Ace,

 

an idea without using RegEx:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(4,418 Views)

Scan from String and Format into String are two of my favorite String functions.  Expanding slightly on Gerd's example,

HTML Scan.png

Bob Schor

0 Kudos
Message 3 of 7
(4,388 Views)

Hi Bob,

 

when parsing HTML files "manually" it seems less error prone (IMHO) to search for some "markers" first and then use ScanFromString on the data just following those markers - that's the reason to use MatchPattern first, followed by ScanFromString…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(4,382 Views)

@AceScottie wrote:

hello. Im having some issues with this.

I have a very long multi line string with a lot of numbers in it. The string is from a HTML so contains a lot of junk as well. 

I want to match the expression <td class="s0" dir="ltr">[0-9].[0-9]</td> 

[0-9].[0-9] being either a 2 digit or 3 digit number with 2 decimal places (100.11 or 99.88) and then take these numbers and add them to an array.

 

i tried matching the expression <td class="s0" dir="ltr">[0-9].[0-9]</td> but tht just returns <td class="s0" dir="ltr"> </td> from the whole match node.

 

 

am i using this right and if so why is it not pulling up the numbers.


Can you provide us with a typical multi line string and the expected match?

 

Ben64

 

note: in your regex the dot will match any character not just the decimal point, to litterally match the decimal point you need to preced it with the escape character \.

0 Kudos
Message 5 of 7
(4,374 Views)

Try this

 

regex.png

 

Ben64

0 Kudos
Message 6 of 7
(4,366 Views)

I posted a snippet that uses Match Pattern to find the stuff between HTML tags here - http://forums.ni.com/t5/BreakPoint/Regular-Expressions-Board/m-p/1193689#M13534

The regex was <(\w*)>(.*)</\1>

 

Right away, I see that your regex looks for exactly one digit after the >, then one of anything then exactly one digit before the next <.  You need to specify repeating character classes and escape the decimal point.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 7
(4,347 Views)