LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search and Replace String with Regex

Solved!
Go to solution

I'm not getting what I expect and I don't see my error here.

I have some strings that, near the end, have a space followed by an "L" or "R" then a period.

I want to insert some text just before the "L" or "R". Here's what I using"

I'm expecting "prefix added L.tif" but I'm getting "prefix added $1.tif"

What am I doing wrong?

0 Kudos
Message 1 of 15
(1,122 Views)
Solution
Accepted by paul_a_cardinale

Hi Paul,

 

Use " (L|R)\." or " ([LR])\." as the search string.

 

[(L)(R)] means any character literally from the list:

(

L

)

(

R

)

 

So there is no capturing group to refer to.

 

Regards,

Raphaël.

Message 2 of 15
(1,114 Views)

If you haven't used it before, try out regex101.com. The "explanation" tab over on the side is a huge help.

 

For example, inputting your regex showed it's looking for the () characters, and has no capture groups:

 

 

2026-03-10 12_24_41-Greenshot.png

 

Using Raphaël's regex shows it dropped the () and gave you a capture group:

 

2026-03-10 12_28_26-Greenshot.png

 

I also use the "Quick Reference" section all the time, because I can never remember the lookahead/lookbehind/other random stuff syntax.

Message 3 of 15
(1,014 Views)

I use rubular.com for my RegEx validations.

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 4 of 15
(938 Views)

I'd include the . in the capturing group:

Reg ex replace 1.png

Probably also the space:

Reg ex replace 2.png

Probably remove excessive spaces:

Reg ex replace 3.png

Message 5 of 15
(823 Views)

I'd personally use a positive lookahead to have the replace string contain exactly what I want to insert:

Search and replace string with regex - positive lookahead.pngSearch and replace string with regex - positive lookahead - result.png

Message 6 of 15
(804 Views)

@raphschru wrote:

I'd personally use a positive lookahead to have the replace string contain exactly what I want to insert:

Search and replace string with regex - positive lookahead.pngSearch and replace string with regex - positive lookahead - result.png


I never remember the syntax of those look arounds when I need them, so I don't use them unless I have to. They are quite powerful..

Message 7 of 15
(682 Views)

wiebe@CARYA wrote:

@raphschru wrote:

I'd personally use a positive lookahead to have the replace string contain exactly what I want to insert:

Search and replace string with regex - positive lookahead.pngSearch and replace string with regex - positive lookahead - result.png


I never remember the syntax of those look arounds when I need them, so I don't use them unless I have to. They are quite powerful..


I often go to https://regex101.com/.

The Quick Reference section is wonderful for finding the syntax I need.

0 Kudos
Message 8 of 15
(670 Views)

@raphschru wrote:

wiebe@CARYA wrote:

@raphschru wrote:

I'd personally use a positive lookahead to have the replace string contain exactly what I want to insert:

Search and replace string with regex - positive lookahead.pngSearch and replace string with regex - positive lookahead - result.png


I never remember the syntax of those look arounds when I need them, so I don't use them unless I have to. They are quite powerful..


I often go to https://regex101.com/.

The Quick Reference section is wonderful for finding the syntax I need.


I have a copy of O'Reilly Python Pocket Reference (9781449357016). 2,- EU at a thrift shop.

It has 2 paragraphs that summarize everything about reg.ex.'s.

 

I don't use it for anything else (since it's about Python).

 

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.

0 Kudos
Message 9 of 15
(606 Views)

wiebe@CARYA wrote:

@raphschru wrote:

wiebe@CARYA wrote:

@raphschru wrote:

I'd personally use a positive lookahead to have the replace string contain exactly what I want to insert:

Search and replace string with regex - positive lookahead.pngSearch and replace string with regex - positive lookahead - result.png


I never remember the syntax of those look arounds when I need them, so I don't use them unless I have to. They are quite powerful..


I often go to https://regex101.com/.

The Quick Reference section is wonderful for finding the syntax I need.


I have a copy of O'Reilly Python Pocket Reference (9781449357016). 2,- EU at a thrift shop.

It has 2 paragraphs that summarize everything about reg.ex.'s.

 

I don't use it for anything else (since it's about Python).

 

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.


C callbacks for PCRE callouts and many other things would be a great feature. If you write it in the IDEA exchange, I will vote for it.

 

There might be some more complicated ways, but for me it would be enough if the Call Library Function Node (CLFN) configuration dialog box provides a parameter type pointer to function" which allows the selection of a DLL (library name or path) and the name of the function. This yould allow to create a DLL/DLL function with LabVIEW an use that function for the callback. Soemthing like this...

 

clfn-callback.png

(Update: changed picture)

 

0 Kudos
Message 10 of 15
(597 Views)