RegEx Help!

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
woodpecker
Posts: 4
Joined: Sat May 31, 2014 6:53 pm

RegEx Help!

Post by woodpecker »

Hi all
From a complete list (C) of text lines I have to cut away some of them (S1, S2, S3, S3..Sn), and paste them (S1, S2, S3..Sn) at the bottom of the remaining list (R).
To select the lines tu cut away, I have defined some RegEx (RE1, RE2, RE3..REn) listed at the top of the complete list (C).
ex. of RegEx list at the top of the complete list (C)
^"B, .?.?.",.............____,56.[9]
^"B, .?.?.",.............____,57.[0-9]
^"B, .?.?.",.............____,58.[0-9]
^"B, .?.?.",.............____,59.[1-9]
^"B, .?.?.",.............____,60.[0-1]
^"B, .?.?.",.............____,83.[0-4]
^"G, .?.?.",.............____,50.[2-9]
^"G, .?.?.",.............____,51.[0-2]
^"G, .?.?.",.............____,52.[4-9]
^"G, .?.?.",.............____,53.[0-9]
^"G, .?.?.",.............____,54.[0-1]
^"Y, .?.?.",.............____,89.[3-9]
^"Y, .?.?.",.............____,90.[0-9]
^"Y, .?.?.",.............____,91.[0-3]
^"Y, .?.?.",.............____,105.[8-9]
^"Y, .?.?.",.............____,106.[0-9]
^"R, .?.?.",.............____,67.[4-9]
^"R, .?.?.",.............____,68.[0-9]
^"R, .?.?.",.............____,74.[0-9]
^"R, .?.?.",.............____,145.[7-9]
^"R, .?.?.",.............____,146.[0-9]
^"R, .?.?.",.............____,194.[5-9]
start of the complete list (C)
"B, 95",TGL0050aMA1h1____,218.6507,2721,17934,1535,3551,3541,217.794,3559,219.3356,5,0.5035,,
"B, 96",TGL0050aMA1h1____,219.7634,315,2166,185,3564,3559,219.3356,3572,220.4476,7,0.6381,,
"B, 97",TGL0050aMA1h1____,221.9001,297,1947,166,3589,3579,221.0459,3595,222.4124,6,0.5153,,
"B, 98",TGL0050aMA1h1____,223.7772,2867,19580,1669,3611,3601,222.9244,3619,224.459,6,0.5201,,
"B, 99",TGL0050aMA1h1____,224.7998,278,1889,160,3623,3619,224.459,3632,225.5661,7,0.6263,,
"B, 100",TGL0050aMA1h1____,227.6073,1995,12506,1062,3656,3646,226.7572,3663,228.2019,5,0.4962,,
"B, 101",TGL0050aMA1h1____,228.7114,180,778,66,3669,3663,228.2019,3677,229.3904,4,0.3912,,
"B, 102",TGL0050aMA1h1____,233.8786,229,1586,134,3730,3720,233.0331,3738,234.5546,6,0.5177,,
. . . <snip>

Macro recorded was:
ctrl+Home
select first line
Cut
ctrl+End
Paste
ctrl+Home
F5 (Find, conditions: Text, RegEx, Direction Down)
canc
ctrl+V (copy the first cut RegEx)
alt+M (Mark all)
Edit, CutOther, BookmarkedLines
canc
esc
ctrl+End
Edit, Insert, PasteAsLines
ClearAllBookmarks
ctrl+Home

Trying to run the macro more than one time for to process the entire list of RegEx lines (RE2, RE3, Re4 ..REn) I realized that the macro does not work, because the RegEx in the first line remain fixed in the macro clipboard memory.
so the Question.:
Is there a way for to Reset the Macro Clipboard Memory in the "Find" option of TXP, forcing the macro to import in the "find" function the RegEx instruction listed in the first line at every loop of the macro?


Alternatively, is it possible to use F5 for to find a list of RegEx (RE1 "OR" RE2 "OR" RE3 etc..) like in this way?
^"B, .?.?.",.............____,56.[9] "OR" ^"B, .?.?.",.............____,57.[0-9] "OR" ^"G, .?.?.",.............____,50.[2-9] "OR" ^"Y, .?.?.",.............____,89.[3-9] "OR" ^"Y, .?.?.",.............____,105.[8-9] "OR" ^"R, .?.?.",.............____,74.[0-9] "OR" ^"R, .?.?.",.............____,145.[7-9]....

then "MarkAll", Cut all together and Paste all together at the bottom of the list (R)?
I will obtain a messy list of lines at the bottom of the file that I have to put in order later, but much better than manually re-run the macro for each RegEx lanes!

How many RegEx can be put in the same "F5 find" window using "OR"?

Since I am a novice with RegEX, can somebody help me in typing an efficient RegEx following the example above?

Any other suggestion is wellcame

Many thanks in advance!
al
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I'm not sure exactly what you're trying to do.

But you can combine regexes with the alternation ("or") operator | (pipe).
So you can combine each of your B, G, Y and R sets of regexes like this:
^"B, .{1,3}",.{13}_{4},(56\.[9]|57\.[0-9]|58\.[0-9]|59\.[1-9]|60\.[0-1]|83\.[0-4])
^"G, .{1,3}",.{13}_{4},(50\.[2-9]|51\.[0-2]|52\.[4-9]|53\.[0-9]|54\.[0-1])
^"Y, .{1,3}",.{13}_{4},(89\.[3-9]|90\.[0-9]|91\.[0-3]|105\.[8-9]|106\.[0-9])
^"R, .{1,3}",.{13}_{4},(67\.[4-9]|68\.[0-9]|74\.[0-9]|145\.[7-9]|146\.[0-9]|194\.[5-9])
And you can combine those like this:
^"B, .{1,3}",.{13}_{4},(56\.[9]|57\.[0-9]|58\.[0-9]|59\.[1-9]|60\.[0-1]|83\.[0-4])|^"G, .{1,3}",.{13}_{4},(50\.[2-9]|51\.[0-2]|52\.[4-9]|53\.[0-9]|54\.[0-1])|^"Y, .{1,3}",.{13}_{4},(89\.[3-9]|90\.[0-9]|91\.[0-3]|105\.[8-9]|106\.[0-9])|^"R, .{1,3}",.{13}_{4},(67\.[4-9]|68\.[0-9]|74\.[0-9]|145\.[7-9]|146\.[0-9]|194\.[5-9])

Note the use of the bounded repetition operator {...} and the backslashing of literal . (dot).
woodpecker
Posts: 4
Joined: Sat May 31, 2014 6:53 pm

Post by woodpecker »

:D
YESS!!
it works!
very condensed RegEx and efficacious.
Thanks also for the suggestion about repetition operator {...} and the backslashing of literal . (dot)
but the use of groups () and of the pipe | is magic!!
Thanks a lot
bye
Post Reply