LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match Pattern with shortest string pattern instead of longest string .*

A sometimes overlooked feature of Match Regular Expression is that you can resize and index the capture groups.

 

Use .*? for a lazy match...

 

Regex non-greedy delimited.png


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 11 of 18
(5,697 Views)

As posted by PhillipBrooks,

you can use Match Regular Expression with the following pattern: .*? to use non-greedy matching (also you can use .+? and {2,5}? ).

Online help: http://zone.ni.com/reference/en-XX/help/371361L-01/lvhowto/regular_expression_patterns/

0 Kudos
Message 12 of 18
(5,685 Views)

@PhillipBrooks wrote:

A sometimes overlooked feature of Match Regular Expression is that you can resize and index the capture groups.

 

Use .*? for a lazy match...

 

Regex non-greedy delimited.png


Philip, if you don't put ab in a capture group you only need to expand the output for (.*?).

To remove the empty spaces before cd and after ef the following regex can be used: ab\s*(.*?)\s*ab (or use TrimWhitespace.vi at the output).

 

If you want to capture all sequences between ab pairs you need to use a lookahead (the second ab pair will not be part of the match), If we have the following sequence: uv tk ab cd ef ab gh jk ab lm op ab

Your regex will match cd ef and lm op ignoring gh jk

Using the following regex ab(.*?)(?=ab) you will match all sub-sequences between ab pairs

 

Using regex-2.png

 

Ben64

 

Ben64

0 Kudos
Message 13 of 18
(5,626 Views)

Suddenly the code is about as complex as my version using "scan strings for tokens" above... 😄

Message 14 of 18
(5,609 Views)

With a known delimiter I would probably lean Spreadsheet string to array.  That said:

 

SimpleExtract.png

Message 15 of 18
(5,586 Views)

@Darin.K wrote:

That said:


I knew that Dr. Regex would come up with a very long line of gibberish that does exaclty what the OP wanted. 😄

Message 16 of 18
(5,566 Views)

Someday, if i should happen to have a massive aneurysm at my desk, and so, exit this world for the next, I can guarantee that there will be unfinished regex code on a block diagram on my monitor.

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 17 of 18
(5,459 Views)

@DavidBoyd wrote:

Someday, if i should happen to have a massive aneurysm at my desk, and so, exit this world for the next, I can guarantee that there will be unfinished regex code on a block diagram on my monitor.


All regular expressions by definition are unfinished and subject to improvement or simplification.


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 18 of 18
(5,399 Views)