Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex/preg_replace to replace subdomain [closed]

i need to use preg_replace to replace two subdomain elements with a single element. my regex skills are virtually nonexistent. the urls are of the form:

user1.common.domain.org
user2.common.domain.org
something.common.domain.org
else.common.domain.org

and need to be replaced with:

newvalue.domain.org
like image 471
lcdservices Avatar asked Jun 15 '11 17:06

lcdservices


2 Answers

preg_replace( '/[a-z0-9]+\.common/i' , 'newvalue' , $url );
like image 113
dynamic Avatar answered Sep 28 '22 19:09

dynamic


Try this:

preg_replace("/.+?(domain.+?)/", "newvalue.$1", "user1.common.domain.org");
like image 32
The Mask Avatar answered Sep 28 '22 20:09

The Mask