12-29-2023 08:58 AM
I have a String where i want to find the string between quotations, for example: My name is "Carl".
I want to return the string Carl, not "Carl". I'm using the regular expression "(.*?)" but the result is "Carl". What should I use? or how can i take those quotations after match the substring?
Solved! Go to Solution.
12-29-2023 09:52 AM - edited 12-29-2023 02:21 PM
It would seem trivial to take the substring right after starting at one and with length 2 digits shorter. You have all the information.
I am sure one of the regex experts will come up with a "one primitive" solution, but I would probably just operate on the bytes, which is often much more efficient (yes, it can be further optimized, e.g. to terminate after the second double quotes.)
12-29-2023 11:32 AM
12-29-2023 03:03 PM - edited 12-29-2023 03:10 PM
Make sure you aren't looking at the whole match output. When you use subexpressions you need to grow the node downward to expose those results.
Also, I think "(.*)" is all you need. I don't think the extra ? is doing anything.
BUT, if your use case is this simple, I would probably avoid using the Match Regular Expression node. It is very heavy weight and is known to sometimes cause problems with EXE builds. paul_cardinale probably has the best solution.
12-29-2023 05:50 PM
@electronic_lab wrote:
I have a String where i want to find the string between quotations, for example: My name is "Carl".
I want to return the string Carl, not "Carl". I'm using the regular expression "(.*?)" but the result is "Carl". What should I use? or how can i take those quotations after match the substring?
Using PCRE without knowing the basics is not a good idea. If you wrote this yourself, how do you know the effect of the question mark? First you learn the function of the parentheses and only sometime later maybe the function with the question mark.
@Lavezza wrote:
Also, I think "(.*)" is all you need. I don't think the extra ? is doing anything.
The ? is essential when it comes to something like: My name ist "Carl", not "Mike". By default, quantifiers are greedy and .* captures the entire string between the first and last quote (Carl", not "Mike) while .*? is ungreedy and stops at the second quote (Carl).
Another idea uses the search 1D array function:
12-29-2023 06:55 PM
I'm new in Labview and couldn't find info about regular expressions, that's why I wrote the question. I will try the diferent purposes but I thought there was a regular expression for that answer.
12-29-2023 07:14 PM
@electronic_lab wrote:
I'm new in Labview and couldn't find info about regular expressions,
Regular expressions have nothing to do with LabVIEW. 😄
12-29-2023 10:04 PM
@electronic_lab wrote:
I'm new in Labview and couldn't find info about regular expressions, that's why I wrote the question. I will try the diferent purposes but I thought there was a regular expression for that answer.
This is one of the websites I use to learn and try out regular expressions
12-30-2023 04:49 AM - edited 12-30-2023 04:51 AM
@electronic_lab wrote:
I will try the diferent purposes but I thought there was a regular expression for that answer.
The closest answer to your initial question is the answer of Lavezza. So there is no need to repeat that again. In other words (copy from here) : Resize the function to view any submatches found in the string.
All other solutions give you some good ideas about pure labview solutions.
12-30-2023 10:22 AM - edited 12-30-2023 10:24 AM
You still need to be careful if the string is not well formed. For example if you have more than two double quotes, things blow up in your face. (A longer regex is needed to fix):
Regular expression tend to be orders of magnitude slower than more direct solutions (such as mine). They also involve writing text code (regex!), which is offensive to graphical programmers (such as me, suffering from regexdyslexia). 😄