LabVIEW Idea Exchange

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

Allow Match Regular Expression to return submatches as an array of string, as an alternative to the growable node behavior

Status: New

I've encountered a programming situation where I may need to call 'Match Regular Expression' where the regex is selected at runtime, and where that regex may potentially have a variable number of submatches to return.  Unfortunately, right now, the submatch count is a compile-time decision based on how far out I grow the node.  I can grow the node to some maximum number of submatches ever expected, and thankfully the node doesn't throw a runtime error if there are fewer, or greater, submatch expressions in the regex.  I'm building the individual returns into a string array for further processing, but it would be much more versatile if the node could return the submatches with a properly-sized string array.

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
11 Comments
Darin.K
Trusted Enthusiast

Good idea.  In the meantime I can point you toward the ability VIs of the Match Regex XNode which will do what you want it to.

 

https://decibel.ni.com/content/docs/DOC-13698

DavidBoyd
Active Participant

Thanks, Darin, I'd read somewhere in the IE research results that the MRE was an Xnode, but didn't realize I could find its source VIs in vi.lib.  A quick look at the PCRE tool you created, very cool - I'll fiddle with it as I have time.

 

Request still stands - indeterminate number of submatches just calls for an array!

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
DavidBoyd
Active Participant

Sooo... after looking at Darin's winning Community submission I realize that the Ability VI for the XNode is exactly what I wanted.  My problem is solved.

 

However, I'm reluctant to use a VI buried in a XNode support folder under vi.lib which is not exposed on the palettes.  What's the risk that a future modification breaks my code?

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Darin.K
Trusted Enthusiast

I'd venture to guess that even if there was a desire to kill off a palette item it would be a slow moving process.

 

Even if they did, the investment is in the RegEx's, there are numerous ways to link to them, from pcre directly, .NET, C++11 and others.

 

The array interface is definitely more convenient in my estimation hence the Kudos.

 

For now you are the instant winner of a workaround.

AristosQueue (NI)
NI Employee (retired)

DavidBoyd: The chance of breaking in a future version is non-zero but minimal. I used to recommend that if you're going to use a non-palette VI that you consider making a copy of the VI outside of vi.lib and linking to that. DarrenN thinks that's being paranoid because if something does happen in a future version, you can always go get the version you want from the previous LV version and make the copy at that time. He's probably right. The XNode support VIs in particular are unlikely to change because of their fairly widespread use, but we make no promises.

 

Darin: That's a really good piece of code! I hadn't seen that one before. Nice work!

Taylorh140
Member

Just FYI there is a HIDDEN GEM in Vi.lib that does this:

Smiley Happy

C:\Program Files (x86)\National Instruments\LabVIEW 2013\vi.lib\regexp\Match Regular Expression_Execute.vi

Smiley Happy

DavidBoyd
Active Participant

Taylor,

 

Yes thanks, that is the path to the ability VI for the MRE Xnode as Darin described above.

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Martin_Henz
Member

Good Idea but it is not complete:

1 - selection of subpatterns by name and by index which could be integrated in the existing "Match Regular Expression.xnode".

2 - input for a subpattern index used for the "before match", "after match" and "match" outputs. The "ignore case" and multiline inputs can be removed (can be specified inside the regular expression). Then there is enough space for this subpattern index.

 

wiebe@CARYA
Knight of NI

Would this do what you're asking for: Add-Match-Regular-Expression-sub-VI ?

 

That one seems to be duplicate, but I've attached a VI that actually does it.

Martin_Henz
Member

Hi wiebe@CARYA

Not really .... I think more into this direction:

snip.PNG