ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match pattern

Solved!
Go to solution

Hello.

 

I am trying to extract data from multiple text documents that go like this "abcdtwy teujh M: +1.2345678e000 mkgtd", and the number +1.2345678e000 is what I want to extract from the string. I can use string subset to separate the number from a single document, but the offset and string length of such data vary in different documents. Therefore, I am thinking of using match pattern to extract the entire string between "M:" and space.

 

I wonder if the match pattern function works in this situation. If so, what regular expression can I write to specify the string between "M:" and space?

 

Thanks a million Smiley Happy.

 

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

Try, without the quotes, "M: ([^ ]+) "

The number you are looking for will be in submatch 1.

Cheers!

0 Kudos
Message 2 of 7
(4,334 Views)

Thanks for replying to my question. I tried the code, but the number wasn't separated from the string; instead, the entire string was placed under "before substring".

 

Please inform me of any mistakes I might have made.Thank you.I appreciate all responses.

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

Try this as regex "\+?-?[.\d]+" (excluding quotes).

 

Regex.png

 

For your reference, find the attached EXAMPLE VI... this I made long back for my reference.


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


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

If your input string will always be the same as what you have provided -- "abcdtwy teujh M: +1.2345678e000 mkgtd" -- you could use the Scan from String function.  You then will have several options for the format string input, the simplest of which is "%s %s %s %f %s" which will also do the string to number conversion for you.

0 Kudos
Message 5 of 7
(4,310 Views)
Solution
Accepted by topic author msuraz27

I tried your test string again and the output worked out OK.  Could you post some example(s) of when it fails ?

 

New Bitmap Image.png

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

Hi 🙂

I realized that if I use match regular expression instead of match patter, the code "M: ([^ ]+)" works perfectly.

Thanks a lot.

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