LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular expression that detects all numbers (integer or float ) in any string ?

Solved!
Go to solution

hi,

i search a regular expression that detects all numbers (integer or float ) in any string ?

thank you for your help.

0 Kudos
Message 1 of 16
(11,458 Views)

A minute on regexr.com gave me this: \b[\+-]?[0-9]*[\.]?[0-9]+([eE][\+-]?[0-9]+)?\b

Prolly not the most efficient and might have holes though.

 

Note that the regex engine you are using needs to accept groups and the \b (Word boundary) escape char. LabVIEWs Match Regular Expression does.

Jon D
Certified LabVIEW Developer.
0 Kudos
Message 2 of 16
(11,444 Views)

it does not work,

Sans titre.png

0 Kudos
Message 3 of 16
(11,430 Views)

Thank you for your attention, but it still does not work,

i want to extract the enteger and double number .

 

Sans titre.png

 

 

 

0 Kudos
Message 5 of 16
(11,419 Views)

imadouino wrote:

Sans titre.png


Of course there is no guarantee that you get a valid number (what if there are multiple commas?)

 

I would just convert to a byte array, autoindex on a FOR loop, and use a conditional output tunnel for lexical class = 3 or value=44 (comma). Convert the resulting byte array back to string and try to scan. (assuming you don't have period as decimal delimiter and no E format, etc.)

Message 6 of 16
(11,401 Views)

I am mistaken in comma, the comma does not count, i want just number 0 to 9 [0-9] in the string.

0 Kudos
Message 7 of 16
(11,398 Views)

You can use the regexr.com page to test various changes to the expression.  In your case you would probably want to remove the leading and trailing \b's because they match on word boundary's. (ie, the match only occurs if the number has a leading and trailing whitespace "a 123 ", and not "a123"  Also, since you use a , instead of a . for decimal separator, you would need to change the [\.]? to ,?.

 

Also, looking over your example, you are just looking to pull digits and one ',' from the incoming stream?  Reason I ask is that your string is not one number, but 4 separate numbers, and you would either need to do multiple regex matches to the string (starting at the prior matches endpoint), or do you just want all the numeric digits as a single string?

Jon D
Certified LabVIEW Developer.
0 Kudos
Message 8 of 16
(11,395 Views)
Solution
Accepted by topic author imadouino

You will need to loop over all matches and concatinate the results.

 

Note there is an empty extra array element that it gets on the last iteration.

Its not a problem here since were concatinating them together, but might be a problem in other cases.

 

 

 

 

0 Kudos
Message 9 of 16
(11,395 Views)
Solution
Accepted by topic author imadouino

@imadouino wrote:

I am mistaken in comma, the comma does not count, i want just number 0 to 9 [0-9] in the string.


That makes it even simpler:

 

Message 10 of 16
(11,385 Views)