LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match nth occurrance

Solved!
Go to solution

Hi all,

 

Using the Match Regular Expression function I would like to match against only the nth occurrance of my regex in my input string. For the life of me I can't see how to do this neatly. I was hoping for a modifier followed by an argument (n) but I just can't figure it. I've been on a lot of the Perl sites and seen some examples but not being a high-level text-based programmer I can't seem to translate them to LabVIEW speak.  Anyone got any ideas? Thanks in anticipation.

 

Regards, GGT.

0 Kudos
Message 1 of 8
(3,336 Views)

Try this.  (LabVIEW 8.2)

 

-Matt

-Matt Bradley

************ kudos always appreciated, but only when deserved **************************




0 Kudos
Message 2 of 8
(3,323 Views)

So fuzzy wuzzy wasn't fuzzy was he?  He may not be fuzzy but he's certainly ingenious!  How simple, as all the best solutions are.  Why didn't I think of that (rhetorical question). Well, if no one comes up with anything better you're on your way to one of those solutions thingys.

 

Regards, GGT.

0 Kudos
Message 3 of 8
(3,317 Views)
Solution
Accepted by GGT

 

The (z) and {7} are the key parts.

 

Jim

Message Edited by jcarmody on 02-24-2009 03:35 PM
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

Download All
0 Kudos
Message 4 of 8
(3,300 Views)

Wow! You guys are good. jcarmody, your's is the sort of solution I was groping in the dark for. Somehow I'd got it into my head that the solution might be linked with the modifier /g. Shows what I know about regexes. Without wanting to appear dimmer than I probably already do, you couldn't walk me through the rest of your regex, could you please? I'm starting to get to grips with regexes but I wouldn't have come to your solution in a month of Sundays.

 

Regards, GGT.

0 Kudos
Message 5 of 8
(3,290 Views)

(?:.*?(z)){7}

 

  1. (?:regex); Non-capturing parentheses group the regex so you can apply regex operators, but do not capture anything and do not create backreferences.
  2. . (dot); Matches any single character except line break characters \r and \n. Most regex flavors have an option to make the dot match line break characters too.
  3. *? (lazy star); Repeats the previous item zero or more times. Lazy, so the engine first attempts to skip the previous item, before trying permutations with ever increasing matches of the preceding item.
  4. (regex); Round brackets group the regex between them. They capture the text matched by the regex inside them that can be reused in a backreference, and they allow you to apply regex operators to the entire grouped regex. 
  5. {n} where n is an integer >= 1; Repeats the previous item exactly n times. 

 

But really, I found it here. http://www.perlmonks.org/?node_id=2150

 

You shouldn't feel dim.  Nobody understands this stuff!

 

Jim 

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 6 of 8
(3,275 Views)

I forgot to ask.

 

Q - Why didn't little Jimmy understand Regular Expresions?

A - Because his mommy wouldn't let him play with matches! Smiley Very Happy Smiley Very Happy Smiley Very Happy 

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 8
(3,271 Views)

"...wouldn't let him play with matches". Ha ha, very witty.  Made me laugh. Thanks for your detailed reply and the link. Appreciated.

 

Regards, GGT.

0 Kudos
Message 8 of 8
(3,249 Views)