Jump to content

A regular Expression Problem


dannyt

Recommended Posts

Hi,

I wonder if anyone could help please help me improve my labview with regard regular expressions.

I am checking serial / part numbers entered on a front panel by operator; when the operator presses enter I do a little check to see if a valid part number has been entred. This is currently implemented and working I am using a matchsub-string vi but the pattern match is far to general and I would like to tighten it.

For example I would like to match MTY2345 MAF2345 PTC2345 CVS2345 in perl or python there is a | (pipe) option that can be used so

(MTY | MAF | PTC | CVS )2345 would work fine, it appears there is no pipe in the labview regular expressions.

I can see a way to implement this using multiple matchsub-string vi's each using the output of the previous one, but I feel if only i could get the correct pattern I could do it with only one matchsub-string vi.

I am using Labview version 7.0

cheers in advance

dannyt

Link to comment

QUOTE(Tomi Maila @ Feb 13 2007, 12:02 PM)

I think it was LV 8.0 that came with new regexp node that works in a very similar way as Perl regexps. Could you consider upgrading to newer LV?

Tomi

ah Labview 8.0 or even better 8.2, I am trying to go in that direction, but you know the old Newtonian law on Software Inertia... a software version bought and paid for should remain in rest until senior management say otherwise :(

As I said I can implement it in 7.0, I was just hoping somebody would tell me I was wrong and there was a way to match it with one single MatchPattern vi if only i got the pattern right.

Link to comment

QUOTE(dannyt @ Feb 13 2007, 01:19 PM)

ah Labview 8.0 or even better 8.2, I am trying to go in that direction, but you know the old Newtonian law on Software Inertia... a software version bought and paid for should remain in rest until senior management say otherwise :(

As I said I can implement it in 7.0, I was just hoping somebody would tell me I was wrong and there was a way to match it with one single MatchPattern vi if only i got the pattern right.

Can you tell us a bit more what kind of expressions you want to match? Is it always a character sequence followed by numbers etc.?

If it is then you could check out the "Match First String" primitive.

QUOTE

Compares each string in
string array
with the beginning of
string
until it encounters a match.

/J

Link to comment

QUOTE(JFM @ Feb 13 2007, 12:27 PM)

Can you tell us a bit more what kind of expressions you want to match? Is it always a character sequence followed by numbers etc.?

If it is then you could check out the "Match First String" primitive.

/J

JFM, Thanks :thumbup: for the Match First String suggestion, that's a nice way of doing this, I had not used this before.

Examples are MTY2345 MAF2345 PTC2345 CVS2345 as you say I can use the match first string to match MTY MAF PTC and CVS build into an array and then just check the number at the end, this is a great deal nicer than what I was planning to do.

cheers

danny

Link to comment

QUOTE(dannyt @ Feb 13 2007, 12:30 PM)

Hi,

I wonder if anyone could help please help me improve my labview with regard regular expressions.

I am checking serial / part numbers entered on a front panel by operator; when the operator presses enter I do a little check to see if a valid part number has been entred. This is currently implemented and working I am using a matchsub-string vi but the pattern match is far to general and I would like to tighten it.

For example I would like to match MTY2345 MAF2345 PTC2345 CVS2345 in perl or python there is a | (pipe) option that can be used so

(MTY | MAF | PTC | CVS )2345 would work fine, it appears there is no pipe in the labview regular expressions.

I can see a way to implement this using multiple matchsub-string vi's each using the output of the previous one, but I feel if only i could get the correct pattern I could do it with only one matchsub-string vi.

I am using Labview version 7.0

cheers in advance

dannyt

why don't you use the vi find regular expresion (under String)

Then you can enter your regualr expresion:

(MTY|MAF|PTC|CVS)2345

But without blanks...

(I hope that this vi is also in LV7, I use LV8.2...)

Link to comment

QUOTE(dannyt @ Feb 13 2007, 11:30 AM)

Many years ago (well about 6) I wrote a vi that interfaced to the Perl Compatible Regular Expressions library for LabVIEW 5.1. It's downloadable from: http://www.crojack.org/labview/pcre-2.08-lv.zip If you're running Windows then there is a precompiled binary, otherwise it's a question of compiling the CIN and linking to a version of libpcre. Basicallly my routine does the same as the one now builtin in LV 8.0+ - except that I did it first :rolleyes: and mine isn't a nice extending node but can handle variable numbers of sub-patterns at run time. It's a long time since I used that version (I rolled the CIN code into a custom dll full of other useful code functions, and the PCRE version is positively prehistoric in internet terms !) so I can't promise that it all still works....

Link to comment

Thanks to everyone for the replies.....

for now I will use the 'Match First String' solution, I like that.

But I have an evaluation copy of Labview 8.2 and oh the Match Regular expression function is sooo nice :thumbup: , there are so many places in our code where this would simplify life

cheers

dannyt

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.