Reputation: 210
I'm trying to build a regex to remove an entire sentence. The phrase is:
www.mydomain.com is the best, in fact it is the best. So visit mydomain.com
I tried the following
\www\.mydomain\.com is the best\, in fact it is the best\. So visit mydomain\.com/
But it doesn't help.
Any advice on this please?
Upvotes: 0
Views: 308
Reputation: 1061
That should be a forward slash at the start, not back. \w
matches whitespace, when I suspect you mean it to be the start delimiter.
Also, commas don't need to be escaped, so change \,
to ,
.
With those changes, it works for me.
*edit*If you're just matching a phrase, you can use \Q...\E to avoid needing to escape all the special characters in it.*
Upvotes: 1
Reputation: 91518
As you don't say what language you're using, here is a perl way to do it:
my $str = q!www.mydomain.com is the best, in fact it is the best. So visit mydomain.com!;
$str =~ s/.*?\.( |$)//;
print $str;
output:
So visit mydomain.com
Php version:
$str = 'www.mydomain.com is the best, in fact it is the best. So visit mydomain.com';
$str = preg_replace('/.*?\.( |$)/', '', $str);
echo $str;
This produces the same output.
Upvotes: 0
Reputation: 11
there is a missing / at the beginning and the end.
in vi the following worls fine:
s/www\.mydomain\.com is the best, in fact it is the best\. So visit mydomain\.com//
Upvotes: 0