LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regex for Search and Replace String

Solved!
Go to solution

Using LabVIEW 2023, I am trying to allow only alpha numeric strings, and dashes with the Search and Replace String function. The regular expression is a simple one as far as they go, but I'm at a loss as to why this doesn't filter the parenthesis, braces and brackets, i.e. ( ) { } and [ ]. I even tried removing the trailing dash just in case it was confusing it as the start of another series, and the result is the same. I set the font used in the block diagram to Consolas so you could see that the zero is NOT a capital letter O. I have also tried the Match Pattern function and got the same result. I have even entered the expression into one of the online RegEx testers sites and it spots exactly the characters I want to filter.

 

TeraTech_0-1747765174323.png

 

 

Here is the regex expression:

[^a-zA-Z0-9-]

 

TeraTech_0-1747763808964.png

 

0 Kudos
Message 1 of 5
(347 Views)
Solution
Accepted by topic author TeraTech

you need to set the replace all flag to TRUE:

bean123_0-1747765532495.png

 

0 Kudos
Message 2 of 5
(335 Views)

😖 That's embarrassing!   Thanks! Any idea how to modify the regular expression to omit multiple consecutive dashes and remove any ending dashes?

0 Kudos
Message 3 of 5
(318 Views)

Try [^a-zA-Z0-9-]|-$|-(?=-)

 

Ben

0 Kudos
Message 4 of 5
(286 Views)
Solution
Accepted by topic author TeraTech

I always forget to set that to true.  My feeling is it should default to true.

You might have to do multiple search and replaces. First replacing consecutive dashes with a single dash, then removing end dashes, then using your original search and replace.  But AI like chatgpt or grok are pretty good at doing this stuff.  just make sure you tell it you are using LabVIEW's search and replace string vi

0 Kudos
Message 5 of 5
(278 Views)