LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expression for match pattern

Hi guys, I need some help.
 
In one part of my test system, I give to the program a sequence of temperatures, which are numbers separated by a comma. Due to a possible error, the user can  forget the coma, and the program gets unexpected values.
 
For example, "20, 70, -10" is a right value, whereas "20 70, -10" would be a wrong one.
Which regular expression will detect this comma absence?
 
Thanx in advance.
0 Kudos
Message 1 of 26
(4,561 Views)

I don't know if there is any expression which can detect a space not preceded by a comma, but in any case I would suggest that you find another way. If you want the users to enter multiple values, let them use an array of numerics or a repeating numeric control. Don't give the user the option to make a mistake.

You can remove and add values from\to the array, control its visible size and control its visible elements by using property nodes.


___________________
Try to take over the world!
0 Kudos
Message 2 of 26
(4,553 Views)

Why not simply use space delimited entries.  This way you avoid having to place a comma.

But the better approach is what tst is recommending.  If you have an Operator (User) Interface, simply have them enter numbers in one manner and format the string within your vi.  This eliminates (reduces?) bad entries.  You can also do entry checking before appending the new value to the string.  Did tst suggest using an array instead of using a string?  (Yes, tst did)   You should consider putting the values into an array9 or arrays?), then you can manipulate the data more efficiently in the future.

JLV

Message Edited by JoeLabView on 09-06-2005 08:13 AM

Message 3 of 26
(4,547 Views)
I agree with tst's comments.  In addition I dont think LabVIEWs regular expressions are powerful enough to do what you are looking for.  LabVIEWs regex's are very much a subset of the real thing.
 
But, aside from this, you would need a negative look behind assertion in order to determine that a comma has been left out...
 
A space followed by anything but not preceeded by a comma:
(?<!,) .
0 Kudos
Message 4 of 26
(4,544 Views)
I dunno about anyone else, but I'd do it this way.....

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 26
(4,538 Views)

Thanks to all. I know that a good solution would be to insert this values in another way. The problem is that the program is allready done, I´m just solving some bugs, and it would be too hard to change the code to update it in that way.

Anyway, thanks for your suggestions!

Message 6 of 26
(4,542 Views)

Shane, looks quite good, but gives False when there is only one value (what can be also possible and correct)

Message 7 of 26
(4,540 Views)
OK, makes it more difficult (and more fun Smiley Very Happy)

My original version failed also when the space was forgotten.  DOH!

Try this version.  It get's complicated cause the scan from string likes ignoring spaces... So we change the spaces 😉

Hope this helps

Shane.

PS The ideas given by others are still a better solution, but if you're stuck........
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 8 of 26
(4,525 Views)

In that case, I would say use Spreadsheet string to array with a space as the delimiter. The commas will be ignored.

This is still not a real solution, because the operator could have other mistakes.

The only really good solution, once again, is not to give the operator the chance to make a mistake. If at all possible, you should modify this to work with numbers and not with strings.


___________________
Try to take over the world!
Message 9 of 26
(4,478 Views)

Yes, Shane. But to have or not the space is not a problem, the only point is the coma, which works as a delimiter. So either (10,-30,15) or (10, -30, 15) are correct. I´ve tried to modify your code by myself and don´t disturb u more (u have allready do a lot), but I get really nothing (I don´t understand what is behind u have doneSmiley Sad)

Is possible to modify it? When not is ok, and i will use this version.

Thanks again.
 
Gat
Message 10 of 26
(4,469 Views)