LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expression for Match Pattern (string) Function

I need to find a variable length string enclosed by brackets and
within a string. Can't seem to get the regular expression right for
the Match Pattern function. I'm able to get the job done using the
Token function, but it's not as slick or tight as I'd like. Does
anybody out there have the expression for this?
0 Kudos
Message 1 of 4
(3,391 Views)
The regular expression is "\[[~\]]*\]" which means:
look for a bracket "\[" (\ is the escape char)
followed by a string not containing a closing bracket "[~\]]*"
followed by a closing bracket "\]". The match string include the brackets

You can also read "Scan from String" with the following format: "%[^\[]\[%[^\[\]]" and read the 2nd output. The brackets are removed from the scanned string.


LabVIEW, C'est LabVIEW

Message 2 of 4
(3,391 Views)
Jean-Pierre Drolet wrote in message news:<5065000000050000007E560000-1007855737000@exchange.ni.com>...
> The regular expression is "\[[~\]]*\]" which means:
> look for a bracket "\[" (\ is the escape char)
> followed by a string not containing a closing bracket "[~\]]*"
> followed by a closing bracket "\]". The match string include the
> brackets
>
> You can also read "Scan from String" with the following format:
> "%[^\[]\[%[^\[\]]" and read the 2nd output. The brackets are removed
> from the scanned string.

Thanks, Jean_Pierre

I did some more experimenting after posting and found that \[.*\] also
works with the match pattern function. Thanks for your input.

sm
0 Kudos
Message 3 of 4
(3,391 Views)
This RE, "\[.*\]" matches the *longest* string included in brackets. If your string has many bracketed expression, for example "AB [CD] EF [GH] IJ", the matched string returned is "[CD] EF [GH]" (from the first left bracket to the last right braket)which may not be the desired result.
That is why in the RE "\[[~\]]*\]" the right bracket is excluded from the search pattern.


LabVIEW, C'est LabVIEW

0 Kudos
Message 4 of 4
(3,391 Views)