LabVIEW Idea Exchange

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

Match regular expression sub matches should return offset and length

Status: Declined

Any idea that has received less than 5 kudos within 5 years after posting will be automatically declined.

Match regular expression will return sub matches for any groups in your expression. So this expression: (\w+)_(\w+) would be sub match 1 and 2.

 

temp.png

 

However, LabVIEW only returns the string of the sub match, not its offset and length. This makes doing replacements on sub matches difficult and technically impossible because you then have to do a search and replace on the sub match and hope there isn't an identical string somewhere in the full string (causing an incorrect replace).

 

Other languages deal with this easily by addressing sub matches by slash codes. For example the first sub match is \1 and the second is \2. So you can say... search for this and replace \1 with that.

 

So I propose:

temp2.png

Stephen B
4 Comments
Darin.K
Trusted Enthusiast

If you go to this example you will see how you can use some "hidden" functionality in vi.lib to get this job done.

 

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

 

 

StephenB
Active Participant

Darin that is great. Thank you! I can use both of those then to get offset and length of each sub match.

 

However I still wish this was just on the xnode instead of hidden VIs that require more work to use.

 

Your regex helper is very impressive. I will use this.

 

Another idea for sure... but I wish Perl RegEx supported variable length look behinds...

Stephen B
Darin.K
Trusted Enthusiast

> However I still wish this was just on the xnode instead of hidden VIs that require more work to use.

 


I am a bit concerned about mile-high nodes if this was always there, but I can imagine an alternate configuration which returns the submatches as three arrays:  strings, offsets, lengths.

Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 5 kudos within 5 years after posting will be automatically declined.