BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expressions Board

I'm back...

 

I'm looking at a regular expression to parse the above text (top shown as '\' code display).

It would not only parse it into an array but weed out the strings so that the result match a given convention.

 

For instance...

 

If you take etsi18_a_28, it would match with etsi18_1_28_R5.  If etsi18_1_28_R5 does not exist, then it would be left out..

You may have guessed that a = 1.  The _R5 at the end of the string refers to a particular model extension.

 

From the above list, the solution would look something like:

 

etsi13_a_28    etsi13_1_28_R5
etsi13_a_56    etsi13_1_56_R5
fcc23_c_40    fcc23_3_40_R5
fcc23_c_50    fcc23_3_50_R5

 

Because non-matching ones are removed.

 

So what I am looking for is a regular expression that can scan through two strings and extract matches and place them into 2 columns (can be a 2D array)... 

 

As I write this I am realizing that I may be asking too much for a regular expression...  Or am I?  I should be able to implement something using wildcards. Which is what I will attempt.   The more I think about this, the more I am tempted to first populate 2 1D arrays and then use a regEx to search the other array for a match..

 

0 Kudos
Message 61 of 150
(7,855 Views)

First, have I misunderestimated the problem?

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 62 of 150
(7,843 Views)

This is a good start.  Thanks Jim.

 

Interesting that we got to nearly the same result with 2 different approaches..

Where I got stuck is how to remove the '\s' entries in the array, which is caused by removing the \r\n and thus leaving an extra '\s' in the middle.

Can we force removing the '\r\n' before removing the extra spaces in the same regular expression?

 

ie:  (do this first) && (do this next)

 

 

The next step will be to weed out the non-matching entries.  That will also require a different regEx.  I will attempt one.  In the meantime, I will review what you posted in more details so that I can learn from it.

 

Thanks 🙂

Message 63 of 150
(7,841 Views)

Wait!! 

 

You got WAY closer to the solution than I thought.

 

The only thing is the middle portion, where a = 1, b = 2 and c = 3.

That's the tricky part...

 

You're good!

Message 64 of 150
(7,836 Views)

Will it always only be a,b or c?  We still need to get that "freqNone" out of there.  This is where I'd expect a better regular expression could replace the a/b/c with a 1/2/3 in one shot, but I haven't found anything yet.

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 65 of 150
(7,825 Views)

Thanks Jim.

 

This is great.  I can take it from here. 

 

That's a clever use of the search string and using the location of the letter as the numeric equivalent.

The [\S]* would have evaded me.. 

 

Thanks!

 

😄

Message 66 of 150
(7,816 Views)

More RegExp fun with submatches here.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 67 of 150
(7,763 Views)

Hi all,

I am reading string output from a device using TCP read and I would like to parse the output using RegEx into an Array. Here is a sample output I am trying to parse. I want each of the values after the tag (Ndx, DiagVal, and so on). Thanks for any suggestions.

 

(Data (Ndx 16429531)(DiagVal 31)(Date 2012-03-08)(Time 09:07:16:400)(CO2Raw 0)(H2ORaw 0)(CO2D 0)(H2OD 0)(Temp -261.132)(Pres 98.4719)(Aux -0.000311381)(Aux2 0.00685038)(Aux3 -0.00622762)(Aux4 0)(Cooler 0.00193281)(CO2MF 0)(H2OMF 0)(DewPt -1)(AGC 100)(H2OAW 0)(H2OAWO 0)(CO2AW 0)(CO2AWO 0))
0 Kudos
Message 68 of 150
(7,716 Views)

What have you tried?  I'm not sure I understand what you're after, but this should be a start.

 

regex.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 69 of 150
(7,711 Views)

Jim, that was quick and amazing. That is exactly what I wanted to do parse the label and value. I was trying something like \(Ndx\s[0-9]+\) and so on. I was getting the whole match right but I was not sure how to separate each part out. Nice way to put it all together with the loop and shift register. Thank you so much.

0 Kudos
Message 70 of 150
(7,695 Views)