LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

regex making my head spin...

I need help coming up with a regular expression to do this search.

 

1. not very familiar with them so if someone wants to point me to a good tutorial, please do. I have tried and just can't get it to work.

2. please step me through your solution so I can understand what the regex is doing

 

I have a string like below. I want to search for, say, the number 16 but ignore the ones in red, find the ones in green.

 

1     : 11 62 33 44 51   ab16ef
16    : 68 44 55 16 22   abcdef

 

 So essentially I'm ignoring everything before the ":" or in the last "column" and also ignoring whitespace. But, I want it to wrap between lines. This is one long string with either a new line or a CR denoting the end of each line, I'm not sure which.

 

I don't want to programmatically strip off the first and last columns first to only leave me with the middle chunk because the string may be millions of lines and that's just added time.

 

Thanks in advance.

0 Kudos
Message 1 of 17
(6,181 Views)

I'm closer...

 

/1[\s]6 | 16/

 

Still finding those before the : and in the last column. Also not wrapping while ignoring the last column

0 Kudos
Message 2 of 17
(6,150 Views)

Here is a web site that is dedicated to this topic.

 

http://www.regular-expressions.info/

Tim
GHSP
0 Kudos
Message 3 of 17
(6,143 Views)

Inside LabVIEW, I'd first search for the colon, and then regex search from there.  Once you're pointing past the colon, "\s16\s" will find the sixteen.

 

For the absolute best tool for learning and practicing regex stuff, all different flavors:

www.regexbuddy.com

0 Kudos
Message 4 of 17
(6,139 Views)

One of the issue is the wrapping between two lines after stripping the alphanumeric part at the end of the line. I doubt this can be done in a single operation. I attached a vi that can do the job it may need a cleanup (I did it rapidly). It is probably not very effective for a million lines string but maybe the regex used will help you.

 

Ben

 

 

 

For regex info you can also look at this site:

 

http://perldoc.perl.org/perlre.html

0 Kudos
Message 5 of 17
(6,117 Views)

What do you want to return?  I've written this that will find the 16s that you're interested in, but I don't know what to return except the locations.  The "names" array is useless, but I left it there anyway.  The "Locations" array shows the character offset after each match (with the -1 at the end as a free gift).

 

The regexp is : *[0-9 ]*(1 *6)

":"         looks for a colon
" *"        looks for zero or more spaces
"[0-9 ]*"   looks for zero or more single digit or a space

"(1 *6)"    looks for the number 1 followed by zero or more spaces, followed by a 6.  The parentheses keep that as a sub match.

 

18915i951B82E66EA2A246

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 6 of 17
(6,103 Views)

Hold on.  I missed one of the 16s.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 17
(6,097 Views)

I've got the location of the missing 16.  It was hunkered down so tightly that I needed to use a pipe to get it out.  Please explain what this VI is supposed to return before I explain the regexp.  I don't know what you need so I don't know how to proceed.

 

Can you provide a larger sample to further test what I've done?

 

 

18947i1CF396594FF1D4CE

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 8 of 17
(6,076 Views)

Wow Jim, this is great!

 

I modified the input string and found an input that tricked your regex. In the attached there should be a 1 6 detected at position 47. I tryed to modified your regex to solve this but have not succeeded yet.

 

Ben

 

18965i41A8A86647C03792

Message 9 of 17
(6,052 Views)

((: *)*[0-9 ]{0,1}(1([ \r\n\sa-zA-Z:]*)6))|(1( *[a-z0-9]*[\r\n][0-9]* *: *)6)

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 10 of 17
(6,038 Views)