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?
You can use
^www[0-9]*\.((?:[^.]*\.)+)
Replace with $1
. See the regex demo . Details :
^
- start of string www[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.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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.