LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to build regular expression

I am trying to build a regular expression that will search the following array of strings for the sequence 3.1

 

 

Read Modem Information:

Device Type .......................... 2
Serial Number ........................ 11437
Primary Phone Number ................. 1800...
Secondary Phone Number ............... 1800...
Modem Software ....................... BOOT.3.1 Jun 17 2004 17:02:26
Bracelet Software .................... 4.0
Validation Number .................... Default
Login Name ........................... Default
Login Password ....................... Default
Case Number .......................... Default
Primary Encryption Key ............... Default        
Secondary Encryption Key ............. Default        
Dialing Format ....................... True
Call In Format ....................... True
Modem Download Flag is Clear ......... True
SCRAM Download Flag is Clear ......... True
SCRAM Char Table Load Flag is Clear .. True
Download Inhibit ..................... True
Exiting Boot (8 sec) ................. Switching to operating memory.
Main Revision ........................ SLCP.3.1 Jun 17 2004 17:02:46
Reset ................................ Complete

This is my first real foray into regular expressions and so I am lost trying to understand the help file.

 

Thanks!

 

Tay

Message Edited by slipstick on 09-25-2008 09:34 AM
0 Kudos
Message 1 of 11
(7,077 Views)

 Maybe I misunderstood what you need, but the following should search an array of strings for your regular expression...

 

Message Edited by Thoric on 09-25-2008 04:00 PM
Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 11
(7,062 Views)

That would match the line with "Modem Software" and "Main Revision".

 

Which 3.1 are you looking for? Are you trying to find a specific line?

0 Kudos
Message 3 of 11
(7,053 Views)
And this way tells you which entries meet the requirement
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 4 of 11
(7,044 Views)

I am actually trying to capture both. I'm using the 'Match Regular expression' vi since the line length may vary on occasion and the value may not always be 3.1

 

Tay

 

Message Edited by slipstick on 09-25-2008 10:24 AM
0 Kudos
Message 5 of 11
(7,039 Views)

Not sure what you mean by the line length may vary, requiring using the "match regular expression". Which string may change? The lengths of the input strings are varying, and the

"regular expression" while a fixed constant in my example could be a control.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 6 of 11
(7,031 Views)

I think the OP was puzzled about how to form a RE.

For the specific case or how to find the exact string "3.1", and to not match anything else, the RE is "3\.1"

 

Why?

For the most part, a RE search string is an exact character match. However things change when certain "special characters" are included in the search string. The RE help message says what they are, but the descriptions can be a bit daunting at first.

 

As a first example of special characters, the RE of "." (The single character fullstop) will match ANY single character. Thus a RE of "3.1" will match "3.1", "301", "3Z1", but not "31" or 3aa1".

 

Another special character is "*". It modifies the match to allow zero or more of the preceeding bit. So "3.*1" matches "3", followed by any number of any character (including no characters), followed by "1". so it will match "31", "301", "3ABC51", "31111111"

 

The action of a special character is cancelled by preceeding it with a backslash. So in the example above "3\.1" matches ONLY the string "3.1"

 

The best way to discover exactly how RE's work is to try some out. Make a VI containing Match Pattern, and suitable controls and indicators. Work through the examples and see how they operate. Now try your own!

 

 

Message 7 of 11
(7,026 Views)
The regular expression to find "3.1" is "3\.1". The point has to be escaped.

Regards,

Wiebe.


Message 8 of 11
(7,014 Views)

Ok, got it. Here's what I did. And I needed to capture three instances of numbers seperated by a period. One of them isn't 3.1.

 

Yes, what I needed help with was formulating the regular expression.

 

Thanks to all!

 

Tay

0 Kudos
Message 9 of 11
(6,994 Views)
> reg expression.png:
> http://forums.ni.com/ni/attachments/ni/170/357893/1/reg expression.png

That looks ok. You could clean up a bit (straighten some lines). Alson (some
unasked for advise):

I'd put the three constants in an array constant, and compare the array with
the result. Then, use array indexing to get the three booleans from it, to
use them for the three cases.

I'd also put the results in a shift register, instead if indicators in the
nested for loop. I'd make another three element array, put it outside both
for loops, make shift registers through the two for loops. Then, compare the
array, use a search 1D array to get an index, and replace the found element
in the new array. That way, it is growable, so you could easilly make 10
compares without having to copy the code ten times! Use an index array after
the for loops to put the resulting array results into the indicators.

I don't know how bug the 2D input array is, but the wait doesn't seem
nessesairy. Comparing 1000 elements should take 1 ms, but with the wait it
will take 5 seconds. The resulting indicators from the RE noe are probably
there for debugging, but you should remove them in the final code. They will
waist lots of processing power...

Regards,

Wiebe.


Message 10 of 11
(6,956 Views)