LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match regular expression between quotations

Solved!
Go to solution

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?

 

0 Kudos
Message 1 of 12
(1,752 Views)

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.)

 

altenbach_0-1703864867089.png

 

 

0 Kudos
Message 2 of 12
(1,743 Views)

n.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 3 of 12
(1,722 Views)
Solution
Accepted by topic author electronic_lab

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.

 

Lavezza_0-1703883591495.png

 

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.

Message 4 of 12
(1,700 Views)

@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:

snip.png

0 Kudos
Message 5 of 12
(1,673 Views)

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.

0 Kudos
Message 6 of 12
(1,659 Views)

@electronic_lab wrote:

I'm new in Labview and couldn't find info about regular expressions, 


Regular expressions have nothing to do with LabVIEW. 😄

0 Kudos
Message 7 of 12
(1,651 Views)

@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 

https://regex101.com/

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 8 of 12
(1,634 Views)

@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.

 

 

0 Kudos
Message 9 of 12
(1,025 Views)

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):

 

altenbach_0-1703953066129.png

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). 😄

0 Kudos
Message 10 of 12
(956 Views)