Deleting everything (to the end of file) after a string

A place to try and solve your RegEx problems.
Post Reply
datalab
Posts: 1
Joined: Tue Sep 11, 2012 3:36 pm

Deleting everything (to the end of file) after a string

Post by datalab »

Hello,
I would appreciate any Regular Expressions help for removing everything after the word "Categories:" for the following text:

Subcontractor
Buyers' Guide
Categories:
Boiler, Hot-Water Heating & Steam Fitting Contractors (C-4);
Fire Protection Contractor (C-20)
General Engineering, General Building & Specialty Contractors (ABC);
Plumbing Contractor (C-37)
Sheetmetal Contractor (C-44)
Ventilating & Air Conditioning Contractor (C-52);
Address:
1029 Ulupono Street
Honolulu, HI 96819
Phone:
808-842-5100
808-848-2703 (fax)
Contact Person:
Mr. Kent Matsuzaki
President
Email:
economyplumbing@hawaii.rr.com
Type of Work
Performed:
Air Conditioning, Plumbing, Steam Piping, Fire Sprinkler, Air Conditioning Service, Refrigeration Piping, welding
Location of Work
Performed:
Oahu

Contractor
License #(s):
BC-318, C-4, C-37, C-52, C-20
User avatar
Fool4UAnyway

Re: Deleting everything (to the end of file) after a string

Post by Fool4UAnyway »

In case you haven't found this or any other solution yourself, perhaps you can find some information in the thread below. The question was phrased almost the same.

"Deleting everything (to end of line) after a certain string"
viewtopic.php?f=7&t=882

You may use something like the expressions below.
Be sure to have the multiline anchors option set correctly (I guess it should be unchecked).

Find:
(yourwordhere).*$

Replace by:
$1

$1 replaces the "yourwordhere" you entered between parentheses and does not so with .*$, which is anything that follows it. In effect, that part will be deleted.
User avatar
Fool4UAnyway

Re: Deleting everything (to the end of file) after a string

Post by Fool4UAnyway »

This is another thread about something similar:

"Remove everything until certain word"
viewtopic.php?f=6&t=963
TimInNY
Posts: 3
Joined: Wed Sep 04, 2013 11:46 pm

Re: Deleting everything (to the end of file) after a string

Post by TimInNY »

Slight change...

Assuming you are working with a file named 'test.txt'

The contents of that file would read:

Line 1
Line 2
Line 3
Delete After Me
Line 5
Line 6
Line 7

Point TextCrawler to the correct file location

Search: (Delete After Me).*$
Replace: $1

Case Sensitive: Up to you
Multi-line Anchors: Unchecked
Dot matches newline: Checked

This should replace 'Delete After Me' and everything that comes after it with 'Delete After Me'.

This should leave the file 'test.txt' reading

Line 1
Line 2
Line 3
Delete After Me
Post Reply