05-19-2017 09:01 AM
hi,
i search a regular expression that detects all numbers (integer or float ) in any string ?
thank you for your help.
Solved! Go to Solution.
05-19-2017 09:10 AM - edited 05-19-2017 09:11 AM
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.
05-19-2017 09:19 AM
it does not work,
05-19-2017 09:27 AM
05-19-2017 09:33 AM - edited 05-19-2017 09:36 AM
Thank you for your attention, but it still does not work,
i want to extract the enteger and double number .
05-19-2017 09:57 AM
imadouino wrote:
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.)
05-19-2017 10:01 AM
I am mistaken in comma, the comma does not count, i want just number 0 to 9 [0-9] in the string.
05-19-2017 10:05 AM
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?
05-19-2017 10:05 AM
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.
05-19-2017 10:10 AM - edited 05-19-2017 10:11 AM
@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: