From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-25-2011 03:45 AM
Hello everyone
I am new to regular expression and I have a very simple question. I use the "read from text file" function to load a Tab delimited file with 3 columns into my VI. Next, the string is converted in array and I use the values.
Nevertheless, I want to develop a "filter" allowing only digits (0-9), colon, comma and point into strings.
Using the "match regular expression" function, I was trying a regular expression like that:
[^0-9]|[^\].[|^:]|[^,]
But it is not working.
Could someone help me with this issue?
Thanks
Dan07
Solved! Go to Solution.
02-25-2011 05:46 AM
02-25-2011 06:07 AM
Here's an alternate method using Match Regular Expression, but a wise man once said "When I find myself facing a regex in a loop, I try to see if my old friend Search and Replace can help."
02-25-2011 04:22 PM - edited 02-25-2011 04:23 PM
Hello
Actually I don't need to modify the string that has "invalid" characters, I just need to identify them instead. Find below a VI testing both methods: Match Regular Expression and Search and Replace String.
Using Match Regular Expression method, I got correct results since all the "valid" values must be identified as "-1" and all the "invalid" values must be identified as positive numbers (offset).
Nevertheless, using Search and Replace String method I got wrong results, since all the strings were classified as "valid" (-1), but "bg" and "03/12/2010" are not "valid".
I will go ahead with Match Regular Expression method because it is working great, but I was just wondering how to fix Search and Replace String method to achieve equivalent results.
Thanks
Dan07
02-25-2011 04:26 PM
Look closely at Jim's Search and Replace Node then look at yours. Notice the missing '*' that means that Regular Expressions are not enabled. Right Click and Select Regular Expression, then try it again.
02-25-2011 05:28 PM - edited 02-25-2011 05:30 PM
Darin K.
You are right about that. I changed it to "Regular Expression" and worked great (attached image). It's interesting to see that Match Regular Expression represents the location of the found string starting at index 1, and Search and Replace String starting at index 0.
Thanks
Dan07
02-28-2011 05:39 AM
@dan07 wrote:
It's interesting to see that Match Regular Expression represents the location of the found string starting at index 1, and Search and Replace String starting at index 0.
They're both using the same index (starting at zero), but they're looking at different things. The offset past replacement from the Search and Replace String function is giving the position in the result string. The offset past match in the Match Regular Expression function is giving the position of the match in the input string.
10-16-2011 03:06 PM
jcardmody,
Couple months ago you helped me with a code to check if the string has just valid characters: digits (0-9), colon, comma and point
Why did you use [^0-9:,\.] ?
Is [^0-9:,.] the same thing?
Why did you use the \ ?
Thanks
Dan07
10-16-2011 04:28 PM
Escaping the '.' is probably just a habit that Jim has gotten into. Outside of an alternative '.' will match any character except newline, so it is easy to get confusing results when actually trying to match a '.' unless you remember to either enclose it in an alternative ([.]) or escape it (\.). Escaping it inside the alternative is unnecessary yet harmless.
10-16-2011 05:10 PM - edited 10-16-2011 05:11 PM
Darin
So, the best option for me would be [^0-9:,][.] ??
Thanks.
Dan07.