How I delete sentence that specific word in it?

Status
Not open for further replies.

ChaoscripT

Active Member
1,005
2010
11
20
I have text file with this pattern:
text text text text text text - Site 1

text text text text text text - Site 2

text text text text text text - Site 3

text text text text text text - Site 5

text text text text text text - Site 1

The word "Site" is change in every sentence.
I want that all where is "Site 1" showed, it's will delete the whole sentence.
How I can do it ?

Regards.
 
14 comments
PHP:
$new_text = preg_replace('/(^.+Site 1$)/mU', '', $text)
This will search for Site 1 at the end of each line, and if it's found, the line will be deleted.
 
@deliteblogger,
Works great,
Now there is any way to do that every words: "Site 1, Site 3, Site 5" will delete ? or just to that :
$new_text = preg_replace('/(^.+Site 1)/m', '', $file);
$new_text = preg_replace('/(^.+Site 3)/m', '', $file);
$new_text = preg_replace('/(^.+Site 5)/m', '', $file);

Regards.
 
Do you want to delete lines which end by 'Site 1' and also delete 'Site x' from the end of each line?
PHP:
$new_text = preg_replace('/(^.+Site 1|Site [0-9]+)/m', '', $file);
 
Thx deliteblogger,
And if I want for example that it will delete all "Site" and number bigger then 19, Site 19/20/21/22 - 40?
Numbers 19-40 only.

Regards.
 
Status
Not open for further replies.
Back
Top