Reputation: 33
Have a real domain names like www.by or www.ru, so for such domains I wanna keep "www.". But for other domains, like www.example.org or www.sub.example.org "www." need to be removed.
I have tried regex such ^(www[0-9]*\.)(\.*){2,}
but is not working...
Have any ideas?
Upvotes: 3
Views: 47
Reputation: 110675
You can replace matches of the following regular expression with empty strings:
^www\d*\.(?=.*\.)
The positive lookahead (?=.*\.)
asserts that the first period is followed later in the string by another period.
Upvotes: 1
Reputation: 626758
You can use
^www[0-9]*\.((?:[^.]*\.)+)
Replace with $1
. See the regex demo. Details:
^
- start of stringwww[0-9]*\.
- www
, any zero or more digits, and a .
((?:[^.]*\.)+)
- Group 1 ($1
refers to this value from the replacement pattern): one or more occurrences of zero or more chars other than a .
and then a .
char.Upvotes: 1