LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expression for match pattern


Chaos,

your VI enters an infinite loop if the strings contains two consecutive minus "--".

See also the string example "Extract Numbers.vi"

Message Edité par Jean-Pierre Drolet le 09-08-2005 04:49 PM



LabVIEW, C'est LabVIEW

0 Kudos
Message 21 of 26
(1,392 Views)
Hmm, quite right.  Now thats annoying behaviour Smiley Happy
 
Ok.  I took a closer look at the different ways to parse out the strings and, while this one may not be the quickest way to get things done, it was able to determine every different kind of delimiter I could think of and got all the data right in my testings.  Could you also test this one to see if I missed anything?
0 Kudos
Message 22 of 26
(1,384 Views)
Last one I posted had a blatent bug in it.  While it did take care of delimiters just fine I forgot to go back and test to make sure plain old comma seperators worked still (it was truncating the first digit of the numbers Smiley Surprised).
 
Interesting problem trying to strip off characters for the parsing.
 
If you strip two at a time delimiters are not an issue but numbers are invalid.  If you only strip one at a time numbers are correct but delimiters with minus signs can be misread as negations.  I rebuilt it last night to, hopefully, address both of these issues by preparsing the false negatives out.  I am still testing with different string inputs but I think this version is solid.
 
 
0 Kudos
Message 23 of 26
(1,376 Views)

Yes, the user should not be burdened with the task of proper formatting, the program should do its best to extract the data from the dirty string.

(I am always annoyed by e.g. web fields for the credit card # that state "no spaces" or similar. Any code should be able to strip spaces from a CC #!)

 

Anyway, I prefer "scan strings for tokens". Here you can give a list of all possible separators and consecutive seperators are contracted by default. I this case, you would use separators " " and ",", but nothing prevents you from listing every ASCII value except "-" and 0..9. Expand as needed. A simple example is attached (LAbVIEW 7.1).

Message Edited by altenbach on 09-09-2005 11:14 AM

Download All
Message 24 of 26
(1,367 Views)
Here's a simple variation that treats everything except [0..9 or -] as delimiter. It clean up most input strings nicely.
 
 
 

 

Message Edited by altenbach on 09-09-2005 12:00 PM

Message 25 of 26
(1,350 Views)
Hi Gatet,
 
Why not just use the Search and Replace String vi to replace all commas with spaces. Then you can either parse the string using space delimiters.
 
If you actually need a comma delimitted string at that point, you can put the new space delimitted string in a loop to keep getting rid of double spaces until there are only single spaces, then replace the single spaces with a ", ".
0 Kudos
Message 26 of 26
(1,332 Views)