LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular expression for middle of string

Solved!
Go to solution

Bit of background. I'm getting both text (can contain numbers) and data (only numbers) from serial. Since I don't know which I'm receiving and when it starts/ends, I'm making the sender send "textSTART###textSTOP" where "###" is what I want to extract. ### can contain text, numbers, new line, carrige return or whatever.

The same for data: "dataSTART###dataSTOP", where ### contains only numbers.

 

I think I should use Match Pattern, but I don't know how to make my regular expression.

 

Any help is appreciated. 

0 Kudos
Message 1 of 19
(6,478 Views)

What is your question exactly?

0 Kudos
Message 2 of 19
(6,473 Views)

What regular expression should I use with the Match Pattern VI to extract ### from a string like "testSTART###textSTOP" where ### can be anything from letters, numbers, and special characters like newline or carrige return?

0 Kudos
Message 3 of 19
(6,465 Views)

What determines whether something is part of #### or a part of the other "text" that appears before STOP?

 

Can you also give a more specific example of what the data might look like?

0 Kudos
Message 4 of 19
(6,458 Views)

Sorry for being vague. "textSTART" and "textSTOP" is what I plan to mark my begging and end of the string I receive.

 

Example:

"textSTARTProgram Ready

Threshold: 127

Prescaler: 64

Baudrate: 115200textSTOP"

 

Other stuff I can receive would be data numbers for which I'll use a different Match Pattern VI. Example:

"dataSTART154613516846135156161dataSTOP"

 

Although the numbers will be in binary form. I'll figure that out later. 🙂

0 Kudos
Message 5 of 19
(6,453 Views)
Solution
Accepted by topic author Surreal

There are many solutions if you only wants to extract the string between your specific delimiters. Here's one solution:

 

extract.png

Message 6 of 19
(6,444 Views)
You might also want to try shorter delimiter string, easier and faster to parse.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 19
(6,427 Views)

If the string does not contain anything outside these "delimiters" and there are exactly two per string, you could simply use scan strings for tokens. You can also add the "dataSTART/STOP"  delimiters to the array to make it universal and look at the beginning of the raw string to determine if you are dealing with a "data" or "text" message.

 

Here's a quick draft.

 

Message 8 of 19
(6,420 Views)

@Surreal wrote:
......

 

I think I should use Match Pattern, but I don't know how to make my regular expression.

......

Here is another solution based on regular expression match

 

multiline_regex.png

Message 9 of 19
(6,408 Views)
Another thought is if you have that much control over how the data is formatted, you could even go with a standard format like json. Then the whole question of parsing goes away since you can convert json strings directly into LabVIEW native datatypes.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 10 of 19
(6,391 Views)