03-27-2020 02:35 AM
I have a string with the structure like this "any characters" + !$abCD + "any characters".
I woud like to match the string !$abCD (This string must include !$)
I intend to use the Match Regular Expression.
Thank you in advance.
03-27-2020 04:27 AM
\!\$abCD will work.
I usually use https://regex101.com to test regexes. It gives direct and clear feedback.
03-27-2020 04:55 AM
plusses part of the string? Or does the next part begin with the quote?
To build on @Thols post
\!\$[^"]* - matches all up until "
\!\$[^+]* - matches all up until +
/Y
03-27-2020 05:26 AM
03-27-2020 05:28 AM
03-27-2020 05:48 AM - edited 03-27-2020 05:48 AM
@Yamaeda wrote:
plusses part of the string? Or does the next part begin with the quote?
To build on @Thols post
\!\$[^"]* - matches all up until "
\!\$[^+]* - matches all up until +
/Y
The expected matching sometimes is #something, $something, %something or !#something, !$something, !%something.
How will the expression be?
03-27-2020 05:52 AM - edited 03-27-2020 05:56 AM
@thols wrote:
Or if you want to catch everything within the pluses:
\+ ([^\)]+) \+
Why do you use this expression [^\)] to catch everything?
and I would like to have the general expression to catch the strings excluding ones inside the quote.
The format of the desired strings has the prefixes such as !#,!$,!%, #,$,% (i.e, !#ABCD)
The input string can have one or more "+"
03-27-2020 08:29 AM
@anhduy92 wrote:
@thols wrote:
Or if you want to catch everything within the pluses:
\+ ([^\)]+) \+
Why do you use this expression [^\)] to catch everything?
and I would like to have the general expression to catch the strings excluding ones inside the quote.
The format of the desired strings has the prefixes such as !#,!$,!%, #,$,% (i.e, !#ABCD)
The input string can have one or more "+"
'roof' is 'not' so [^)] matches everything _except_ end parenthesis. Then, as it's an end parenthesis after that, it'll match everything within a parenthesis and include the end parenthesis. If you only search for ')' it's usually greedy and'll grab the last one in the string. (There's an option that can make it 'lazy' and grab the first one).
/Y
03-27-2020 08:33 AM
The lazy operator is .*? so in this case you should be able to use:
\+ (.*?+) \+
03-27-2020 10:57 AM
This page (Rexegg: Mastering Quantifiers) might be useful when reading about lazy and greedy matching.
Remember that LabVIEW uses the PCRE library for regular expressions (at least when it is considering real regular expressions - sometimes LabVIEW has nodes that have regular-ish expressions with limited syntax but often faster execution: see the help for Match Pattern for an example)