All Forums Aster
mzuo 2 posts Joined 11/13
10 Jul 2014
Aster regexp: how to delete 5 lines before certain words

I would like to delete several lines before certain words using reqexp.
For example in the following email, I want to delete 5 lines above the word 'fax', what should I do?
email: Hi All,
as a reminder, most courses have been loaded into your learning center.these classes must be completed by Jul 9th. now is a great time to complete the course work.
Thanks,
Judy
market administrative manager
750 b street
phone 888-888-8888, fax 800-000-0000
 
I tried regexp_replace(email, '^(.?)(\r\n[ ]\r\n.[fax].$)','\1'), but it delete everything after 'Hi All'.
Thanks ahead for help!

dnoeth 4628 posts Joined 11/04
11 Jul 2014

I can't spot where you specify 5 lines, but this might be due to the forum software stripping off some meta characters...
You want to keep the line with 'fax' in it, including the phone number?
I would do it like this using non-matching lookaheads (untested, but should work on Aster, too):

regexp_replace(email, '(?=.*)(\n.*){5}(?=\n.*fax.*)','')

If there are less than 5 lines this will not remove anything, if you want all lines removed {1,5} instead of {5} should work

Dieter

mzuo 2 posts Joined 11/13
11 Jul 2014

Thanks Dieter,
I tried your code

regexp_replace (email, '(?=.*)(\n.*){1,5}(?=\n.*fax.*)','')

But it delete everything in the email but the first line and end up with
Hi All,
fax 800-000-0000

 
Thanks,
Miao
 

You must sign in to leave a comment.