From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
SteenSchmidt

Regular expression should support grouping by parentheses as well as the empty string constant

Status: Completed
This idea is already in LV

Regular expressions in LabVIEW supports parentheses for partial matches, but this fails if your partial match is a set of operators.

 

Let's say I want to match "XYZ_Level" or "Level", where XYZ can be any number of characters including an empty string, the underscore must be there if XYZ is different from an empty string. These strings are valid candidates for instance:

 

"Level"

"_Level"

"a_Level"

"much:more_Level"

 

These aren't:

 

"aLevel"

"abc_defLevel"

 

I'd construct a regular expression as input to the Match Pattern primitive like this then: "(.*_)?Level", but this fails matching any of the good examples above. I think the parentheses fail to parse correctly when they contain operators? I have also tried specifying a partial match using the pipe character, like this: "(.*_|)Level", but this won't work either, probably because I need something on the right hand side of the pipe to tell the regex parser that the alternative is an empty string. An empty string is usually denoted by the epsilon character in regular expressions, but LabVIEW doesn't recognize that.

 

So, (unless I'm mistaken) I'd suggest LabVIEW to support parenthese in regular expressions as means of grouping anything including operators, not only substrings.

 

Cheers,

Steen

CLA, CTA, CLED & LabVIEW Champion
3 Comments
dthor
Active Participant

Have you tried the Match Regular Express primitive?

 

The Match Pattern primitive is a dumbed-down version of POSIX RegEx: it allows only the most common expressions so that speed and eficiency are increased.

SteenSchmidt
Trusted Enthusiast

Oh boy, I never knew the difference between these two primitives in regard of regular expression support. And it is even written in detailed help.

 

Match Regular Expression works with my expression. Thanks!

 

Cheers,

Steen

CLA, CTA, CLED & LabVIEW Champion
JordanG
NI Employee (retired)
Status changed to: Completed
This idea is already in LV