LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

match pattern tilde ~ for exclusion not working

hello,

i am trying to use the match pattern with ~ for exclusion as follows

 

string1 = ERROR_SHOTDATA_10.rsd

string2 = BQERROR_SHOTDATA_10.rsd

 

pattern = [~BQ]ERROR_SHOTDATA ( i want to find string1 with this pattern)

 

match pattern cannot find string 1, any reason wy the exclusion not working , is my regex wrong?

0 Kudos
Message 1 of 10
(4,677 Views)

I don't use regex as much as I should and I couldn't figure out how to do what you were trying to do in the way you were trying to do it but here's a regex that finds string 1 but not string 2.

 

^(ERROR_SHOTDATA_)[0-9]{1,2}(\.rsd)

 

I assumed your filename might have a number between 0 and 99 and not always "10".

 

Remove the leading caret to fing the properly formed portion of the (presumably) corrupted string 2.

0 Kudos
Message 2 of 10
(4,650 Views)

thanks

 

your regex is not finding any, and even if i remove caret, it will find both BQERROR and ERROR ,

the strings are in array and i have regexes for each also in array and i am using for loops to go through strings and regexes, all other strings have some uniquie name in them so its able to match pattern with exact words except these two.

 

thats why i want to exclude [~BQ], but for reasons i  cannot understand its not matching it.

 

i have a different folder whose contents can have

 

string1 = serial-mmddyy-hhmmsssss-ERROR_SHOTDATA_10.rsd

string2 = serial-mmddyy-hhmmsssss-BQERROR_SHOTDATA_10.rsd

 

so i still want to use only 1 regex for both folders and still find either ERROR or BQEROR

0 Kudos
Message 3 of 10
(4,639 Views)

I am not that good in regex, but here is something you may try:

(?<=BQ)ERROR_SHOTDATA.*

0 Kudos
Message 4 of 10
(4,617 Views)

chembo a écrit :

I am not that good in regex, but here is something you may try:

(?<=BQ)ERROR_SHOTDATA.*


This will match the rest of string 2 after BQ, to match string 1 use (?<!BQ)ERROR_SHOTDATA.*
Ben64
0 Kudos
Message 5 of 10
(4,585 Views)

it gives match = QERROR_SHOTDATA

0 Kudos
Message 6 of 10
(4,576 Views)

freemason a écrit :

it gives match = QERROR_SHOTDATA


It works pretty well for me, did you use an exclamation point "!"

 

Just remember, I used match regular expression, not match pattern.

 

Ben64

 

 

0 Kudos
Message 7 of 10
(4,562 Views)

ok it works on match regex, but not on match pattern,

it still bugs me that my original try with ~ doesnot work, it looks as simple as the help file indicates, what could be wrong?

 

 

Help-->Match Pattern Function

 

The longest string within parentheses but not containing any parentheses within it  ([~()]*)

0 Kudos
Message 8 of 10
(4,555 Views)

Read the detailed help file for Match Pattern.  It does NOT handle all possible regular expressions. There is a subset of special characters that it accepts. It may be that your expression is not in the subset.

 

Lynn

0 Kudos
Message 9 of 10
(4,549 Views)

As Lynn mentioned, Match Pattern doesn't implement the full Regex syntax, but only implements a subset of it and that even sometimes in a special way.

 

Your search has however one big problem. The [~BQ] part already matches the entire ERROR_SHOTDATA10.rsd string leaving nothing for the Match Pattern to match the ERROR_SHOTDATA pattern that follows so ending up with nothing.

 

Match Pattern only can indirectly be used to detect your specific request. Basically you would have to search for ERROR_SHOTDATA and also check the string in the "before substring" output to not end in your BQ string (basically using Match Pattern again with the BQ$ search pattern and checking offset past match to be < 0.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 10
(4,538 Views)