Page 1 of 1

TextPad regex to clean up document

Posted: Mon Aug 17, 2009 7:17 pm
by Babscoole
Looking for some help with regex. I've a text document that I need to extract some information out of, while discarding the rest. It's made more difficult by the fact that data is line wrapped. What I need is any instance of six digits (numbers) in a row. All instances of this are also surrounded by single quotes if that helps. Snippet of the data pasted below:

** Error [ 202 ] ** þRecord '251374' is not on fileþ ** Error [ 202 ] ** þRecor
d '251375' is not on fileþ ** Error [ 202 ] ** þRecord '227430' is not on fileþ
** Error [ 202 ] ** þRecord '227433' is not on fileþ ** Error [ 202 ] ** þRecord
'251473' is not on fileþ ** Error [ 202 ] ** þRecord '251474' is not on fileþ *
* Error [ 202 ] ** þRecord '251477' is not on fileþ ** Error [ 202 ] ** þRecord
'251478' is not on fileþ ** Error [ 202 ] ** þRecord '251480' is not on fileþ **
Error [ 202 ] ** þRecord '251482' is not on fileþ ** Error [ 202 ] ** þRecord '
171543' is not on fileþ ** Error [ 202 ] ** þRecord '171544' is not on fileþ **
Error [ 202 ] ** þRecord '171545' is not on fileþ ** Error [ 202 ] ** þRecord '1
71546' is not on fileþ ** Error [ 202 ] ** þRecord '171547' is not on fileþ ** E
rror [ 202 ] ** þRecord '171548' is not on fileþ ** Error [ 202 ] ** þRecord '17
1549' is not on fileþ ** Error [ 202 ] ** þRecord '171550' is not on fileþ ** Er
ror [ 202 ] ** þRecord '171551' is not on fileþ ** Error [ 202 ] ** þRecord '171
552' is not on fileþ ** Error [ 202 ] ** þRecord '171553' is not on fileþ ** Err
or [ 202 ] ** þRecord '171554' is not on fileþ ** Error [ 202 ] ** þRecord '1715
55' is not on fileþ ** Error [ 202 ] ** þRecord '131551' is not on fileþ ** Erro
r [ 202 ] ** þRecord '171556' is not on fileþ ** Error [ 202 ] ** þRecord '26758
8' is not on fileþ ** Error [ 202 ] ** þRecord '123584' is not on fileþ ** Error
[ 202 ] ** þRecord '251645' is not on fileþ ** Error [ 202 ] ** þRecord '227655
' is not on fileþ ** Error [ 202 ] ** þRecord '219724' is not on fileþ ** Error
[ 202 ] ** þRecord '219725' is not on fileþ ** Error [ 202 ] ** þRecord '219726'
is not on fileþ ** Error [ 202 ] ** þRecord '219727' is not on fileþ ** Error [
202 ] ** þRecord '267738' is not on fileþ ** Error [ 202 ] ** þRecord '131725'
is not on fileþ ** Error [ 202 ] ** þRecord '131748' is not on fileþ ** Error [
202 ] ** þRecord '131755' is not on fileþ ** Error [ 202 ] ** þRecord '235796' i
s not on fileþ ** Error [ 202 ] ** þRecord '195865' is not on fileþ ** Error [ 2
02 ] ** þRecord '195866' is not on fileþ ** Error [ 202 ] ** þRecord '195867' is
not on fileþ ** Error [ 202 ] ** þRecord '195868' is not on fileþ ** Error [ 20
2 ] ** þRecord '195869' is not on fileþ ** Error [ 202 ] ** þRecord '195870' is
not on fileþ ** Error [ 202 ] ** þRecord '195871' is not on fileþ ** Error [ 202
] ** þRecord '195872' is not on fileþ ** Error [ 202 ] ** þRecord '195873' is n
ot on fileþ ** Error [ 202 ] ** þRecord '195874' is not on fileþ ** Error [ 202
] ** þRecord '195875' is not on fileþ ** Error [ 202 ] ** þRecord '195876' is no
t on fileþ ** Error [ 202 ] ** þRecord '195877' is not on fileþ ** Error [ 202 ]
** þRecord '195878' is not on fileþ ** Error [ 202 ] ** þRecord '195879' is not
on fileþ ** Error [ 202 ] ** þRecord '259887' is not on fileþ ** Error [ 202 ]

Posted: Tue Aug 18, 2009 1:33 am
by Bob Hansen
Good sample of "before" data, Please example of the "after" data thay you want.

Posted: Wed Aug 19, 2009 4:45 am
by Babscoole
Looking for an end result like:

251374
251375
227430
227433
251473
251474
251477
251478

I pretty much want to dump everything except the six digit number strings.

Thanks.

Posted: Wed Aug 19, 2009 3:31 pm
by Bob Hansen
Here is a three step solution. (Could make into a macro and assign a hot key to do with one key....)

Step 1 ( prepare to make consistent lines.)
Search for: \n
Replace with: nothing

Step 2 (make consistent lines)
Search for: \*\* Error
Replace with: \n** Error

Step 3 (extract the six digits)
Search for .*([0-9]{6}).*
Replace with: \1

Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------