LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Match Pattern string, ignoring spaces between two specified characters

Solved!
Go to solution

Hello!

 

I am attempting to pattern match strings encapsulated in quotations using Match Pattern. I need to be able to differentiate between the start and end quotation mark in a string, so I'm trying to use Match Pattern to detect if a quotation mark has a string immediately following or preceding it.

 

I have patterns for the following:

(For the following set of patterns and resulting strings, entries will be placed on new lines rather than typing out escape characters for quotation marks)

 

any # of quotation marks followed by any character
^["]+.


start of quotation preceded by space:

matches ' "example"' in:

this is an "example"
[\t \r \n \s]+["]+

 

What I need:

A pattern to match any number of quotation marks, followed by any number of characters except white spaces

I attempted to create a regular expression starting with a space character, \s.


What I have tried:
["]+[^\s]

 

What I expect

For the string:

" this is a string" ""and so is this""

 

I want to get the second set of starting quotes and first word, ""and but I keep getting only the first quotation mark, despite there being a space between it and the next alphanumeric character.

 

I also tried specifying a range of acceptable ascii character codes but that didn't produce a match at all.

["]+[\23-7D]

 

I've tried this with both Match Pattern and Match Regular Expression. Could someone point out what I'm doing wrong? I think I'm misunderstanding how the specified pattern works - I want to specify a set of characters that must occur sequentially for a match, rather than an OR statement.

 

I also tried encapsulating the whole expression in a single set of brackets but that didn't work either

["+\23-7D]

 

Any tips would be great!

Thanks

 

Using Labview 2022, Windows 10
0 Kudos
Message 1 of 7
(3,364 Views)

I can't exactly work out what you want in general (I'll maybe try reading again!), but regarding this:


@AllisonSCJ wrote:

I think I'm misunderstanding how the specified pattern works - I want to specify a set of characters that must occur sequentially for a match, rather than an OR statement.


you need a group, not a set of options. Either just write the sequential characters (good for one set), or if they can be repeated, enclose them in () characters (opening and closing parentheses, difficult to work out how to best describe literal characters!).

 

This will also create a capture group, you can avoid this with a "non-capturing" group, I believe, but LabVIEW has some strange-ish behaviour with something like this (I don't remember exactly what... sorry) so you might need some trial and error, or to accept the capture and just ignore the group.

 

You'll want to use Match Regular Expression for these, almost certainly. The Match Pattern can do some stuff quite well (and is apparently faster) but usually falls short for me on more complicated situations when you have groups of things to check.


GCentral
Message 2 of 7
(3,311 Views)

deceased_0-1619515672126.png

Is this what you were looking for?

 

 

0 Kudos
Message 3 of 7
(3,301 Views)

Interesting... I've tried using the expression you have here already, but with one small difference.

If I use a single set of quotation marks for the first string, the expression evaluates properly.

AllisonSCJ_1-1619528141124.png

AllisonSCJ_0-1619528573521.png

 

If it's a set of double quotes, the expression returns the string with a space between my quote and word.

I had assumed that the expression ["]+[^\s] would evaluate for all duplicated ["] characters before moving on to the 'any character but space' portion, but this doesn't appear to be the case; for the specified expression a set of double characters is meeting the requirements despite being followed by a space.

Is there any way to force the behavior I want, or will I have to parse for the quotation marks, and then check for a space in a separate match?

 

 

Using Labview 2022, Windows 10
0 Kudos
Message 4 of 7
(3,283 Views)
Solution
Accepted by topic author AllisonSCJ

Try

 

 ["]+[[:alnum:]]+

 

This should match n lots of "

followed by n lots of alphanumeric characters which will stop when it hits the whitespace.

Message 5 of 7
(3,270 Views)

Thank you!!

I was completely unfamiliar with POSIX Bracket Expressions so I didn't know this was something available to me.

This is what I needed!

 

EDIT:

There are other characters I need to match outside of alphanumeric, but this solution puts me on the right path by giving me a tool I didn't even know was at my disposal. So I'm marking this as the solution.

Using Labview 2022, Windows 10
Message 6 of 7
(3,263 Views)

The resource I use for testing regular expressions is: www.regex101.com

 

Leave the "flavor" set to PCRE (perl compatible regular expressions) as that's what LV uses.

 

Have fun 🙂

 

0xDEAD

 

 

Message 7 of 7
(3,181 Views)