LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular expression global modifier

I have a string which is comma and space separated. I want to pick all the text between ,\s token.

Regular expression I used is ([,\s])+

I then check if end of string is reached and keep iterating through loop ( to set global modifier). Issue is that as I am picking before match string, the last value never get saved in the output array.

 

String to parse:

Index 0 -> 100, 200, 300, 400, 500, 600, 1, 4, 23, 45

Index 1 -> 6000

 

 

 

Output needed is 1D array of string (11 elements) starting from 100 till 6000

 

The other solution I see if using spreadsheet string to array function but am looking to get this done using regular expressions.

 

0 Kudos
Message 1 of 8
(3,812 Views)

Hi rkapoor,

 

The reason why you are not seeing the last element at the output array is because you are only adding the "Before Match" strings. So when the program gets to the last colon ',' at 23,45 it will add the 23 to the array, but in the next iteration it will not find another colon so there is no text to show.

You can solve this in an easy “informal” way by simply adding a colon at the end of the string, or by finding a way to load the last number (like in the attached image)

 

Hope this helps. Good luck!!

0 Kudos
Message 2 of 8
(3,755 Views)

@rkapoor wrote:

I have a string which is comma and space separated. I want to pick all the text between ,\s token.

Regular expression I used is ([,\s])+

I then check if end of string is reached and keep iterating through loop ( to set global modifier). Issue is that as I am picking before match string, the last value never get saved in the output array.

 

String to parse:

Index 0 -> 100, 200, 300, 400, 500, 600, 1, 4, 23, 45

Index 1 -> 6000

 

 

 

Output needed is 1D array of string (11 elements) starting from 100 till 6000

 

The other solution I see if using spreadsheet string to array function but am looking to get this done using regular expressions.

 


If "Index 0 -> " is part of your string your code will not eliminate it. What is the purpose of the convertion to capital letters when you want to match numbers? You should post your code instead of a picture of it, it will be easyer for people to help. Supposing the numbers you want are either always immediatly followed by a comma, before an end of line or at the end of the string the following code should do what you want.

 

Ben64

 

regex1.png

Message 3 of 8
(3,721 Views)

Sorry here is more information:

 

Index 0 is not part of string. Although I stated just the numbers, incoming strings are not always numbers but common across is that they are either ,\s delimited or just one string.

Another possible strings combination is XXXX-Y0100-354, 100, TTTT-M0123-846

so need tokenize using ,\s

 

0 Kudos
Message 4 of 8
(3,704 Views)

rkapoor a écrit :

Sorry here is more information:

 

Index 0 is not part of string. Although I stated just the numbers, incoming strings are not always numbers but common across is that they are either ,\s delimited or just one string.

Another possible strings combination is XXXX-Y0100-354, 100, TTTT-M0123-846

so need tokenize using ,\s

 


Try using replacing the regex by the folling one in my code:

[^\s,]+

 

Ben64

0 Kudos
Message 5 of 8
(3,689 Views)

JLZam

 

That's comma.   Not a colon which is :

0 Kudos
Message 6 of 8
(3,682 Views)

These might be useful.

Excellent tutorial and cheat sheet

Regex builder put your expression in and test it out live on your text

 

0 Kudos
Message 7 of 8
(3,663 Views)

You're right. Thank you! 🙂

0 Kudos
Message 8 of 8
(3,629 Views)