01-13-2012 09:22 AM
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..
01-13-2012 10:02 AM
01-13-2012 10:17 AM - edited 01-13-2012 10:23 AM
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 🙂
01-13-2012 10:25 AM
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!
01-13-2012 11:09 AM - edited 01-13-2012 11:12 AM
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.
01-13-2012 11:36 AM
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!
😄
02-23-2012 02:48 PM
03-08-2012 09:21 AM
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))
03-08-2012 09:41 AM - edited 03-08-2012 09:47 AM
03-08-2012 12:46 PM
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.