$re = '/^(((((.+\.)*(msedge))|((((.+\.)*(scsquery\-ss\-us))|((.+\.)*(scsquery\-ss\-eu))|((.+\.)*(scsquery\-ss\-asia))|((.+\.)*(scsinstrument\-ss\-us))|((.+\.)*(skypemaprdsitus)))\.(trafficmanager))|((.+\.)*(msftauth))|((((((((.+\.)*(policykeyservice)))\.(dc)))\.(ad)))\.(msft))|((.+\.)*(phonefactor))|((((((((.+\.)*(informationprotection)))\.(hosting)))\.(portal))|((.+\.)*(amp)))\.(azure))|((((((.+\.)*(ecn)))\.(dev)))\.(virtualearth))|((((.+\.)*(apis)))\.(live))|((((.+\.)*(spoprod\-a)))\.(akamaihd))|((((.+\.)*(cdn)))\.(onenote))|((.+\.)*(msecnd))|((.+\.)*(msftauthimages))|((((((((.+\.)*(officecdn)))\.(microsoft)))\.(com)))\.(edgesuite))|((.+\.)*(msauth))|((((.+\.)*(mlccdnprod)))\.(azureedge))|((.+\.)*(msauthimages))|((((((.+\.)*(insertmedia)))\.(bing))|((((.+\.)*(videocontent))|((.+\.)*(videoplayercdn))|((.+\.)*(contentstorage))|((.+\.)*(video)))\.(osi))|((((.+\.)*(support)))\.(content))|((.+\.)*(cdn))|((.+\.)*(attachments))|((.+\.)*(suite)))\.(office))|((.+\.)*(windows)))\.(net))|((((((.+\.)*(appsforoffice))|((.+\.)*(c1))|((.+\.)*(crl))|((((.+\.)*(r)))\.(office))|((.+\.)*(aria))|((.+\.)*(technet))|((.+\.)*(officecdn))|((.+\.)*(officeredir))|((.+\.)*(officepreviewredir))|((.+\.)*(office15client))|((.+\.)*(go))|((.+\.)*(msdn))|((((.+\.)*(activation)))\.(sls))|((.+\.)*(support))|((.+\.)*(compass\-ssl))|((.+\.)*(docs))|((((.+\.)*(events)))\.(data))|((.+\.)*(officeclient)))\.(microsoft))|((.+\.)*(outlook))|((.+\.)*(microsoftonline))|((((.+\.)*(secure)))\.(skypeassets))|((.+\.)*(sharepointonline))|((((.+\.)*(informationprotection))|((.+\.)*(management))|((.+\.)*(adhybridhealth)))\.(azure))|((((.+\.)*(g))|((.+\.)*(officeapps))|((((.+\.)*(client)))\.(hip)))\.(live))|((.+\.)*(onenote))|((((.+\.)*(\-myfiles))|((.+\.)*(\-files)))\.(sharepoint))|((((.+\.)*(admin))|((.+\.)*(www)))\.(onedrive))|((.+\.)*(o365weve))|((((.+\.)*(platform)))\.(linkedin))|((.+\.)*(azurerms))|((((.+\.)*(prod))|((.+\.)*(shellprod)))\.(msocdn))|((.+\.)*(microsoftonline\-p))|((((.+\.)*(cdn)))\.(optimizely))|((((.+\.)*(quicktips)))\.(skypeforbusiness))|((((.+\.)*(ajax)))\.(aspnetcdn))|((.+\.)*(aadrm))|((((.+\.)*(products))|((.+\.)*(delve\-gcc))|((.+\.)*(support))|((.+\.)*(templates))|((.+\.)*(outlook))|((.+\.)*(delve))|((((.+\.)*(webshell)))\.(suite)))\.(office))|((.+\.)*(office365))|((.+\.)*(sfbassets))|((((((.+\.)*(skydrive)))\.(wns)))\.(windows))|((.+\.)*(skype)))\.(com))|((((.+\.)*(svc))|((((.+\.)*(auth)))\.(gfx))|((.+\.)*(aka))|((.+\.)*(mstea))|((((.+\.)*(assets)))\.(onestore))|((((.+\.)*(oneclient)))\.(sfx)))\.(ms)))$ /xm';
$str = 'aadrm.com
account.activedirectory.windowsazure.com
acompli.net
ad.atdmt.com
adhybridhealth.azure.com
adl.windows.com
ajax.aspnetcdn.com
aka.ms
appex-rf.msn.com
assets.onestore.ms
assets-yammer.com
atp.azure.com
auth.gfx.ms
autologon.microsoftazuread-sso.com
azure.net
azureedge.net
azurerms.com
bing.com
bit.ly
by.uservoice.com
c.bing.net
cdn.optimizely.com
clientconfig.microsoftonline-p.net
cloudapp.net
ctldl.windowsupdate.com
dc.services.visualstudio.com
ecn.dev.virtualearth.net
eus-www.sway-cdn.com
eus-www.sway-extensions.com
excelbingmap.firstpartyapps.oaspapps.com
firstpartyapps.oaspapps.com
graph.facebook.com
hockeyapp.net
informationprotection.azure.com
isrg.trustid.ocsp.identrust.com
live.com
live.net
login.windows-ppe.net
lync.com
management.azure.com
mem.gfx.ms
microsoft.com
microsoftonline.com
microsoftonline-p.com
microsoftstream.com
msappproxy.net
msauth.net
msauthimages.net
msecnd.net
msedge.net
msftauth.net
msftauthimages.net
msftidentity.com
msidentity.com
msocdn.com
mstea.ms
o365weve.com
office.com
office.net
office365.com
officecdn.microsoft.com.edgesuite.net
oneclient.sfx.ms
onedrive.com
onenote.com
onmicrosoft.com
outlook.com
outlook.uservoice.com
outlookmobile.com
partnerservices.getmicrosoftkey.com
peoplegraph.firstpartyapps.oaspapps.com
phonefactor.net
policykeyservice.dc.ad.msft.net
portal.cloudappsecurity.com
prod.firstpartyapps.oaspapps.com.akadns.net
secure.skypeassets.com
sfbassets.com
sharepoint.com
sharepointonline.com
skydrive.wns.windows.com
skype.com
skypeforbusiness.com
social.yahooapis.com
spoprod-a.akamaihd.net
staffhub.ms
staffhub.uservoice.com
svc.ms
sway.com
symcb.com
symcd.com
telemetryservice.firstpartyapps.oaspapps.com
trafficmanager.net
tse1.mm.bing.net
view.atdmt.com
wikipedia.firstpartyapps.oaspapps.com
windows.net
windowsupdate.com
wus-firstpartyapps.oaspapps.com
wus-www.sway-cdn.com
wus-www.sway-extensions.com
yammer.com
yammerusercontent.com
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php