Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
^(.*?)\.?(([^.]*)(?:(?:\..{2,3})|(?:(?:\..{2,3})(?:\..{2}))))$
/
gim

Description

takes www.yourdomain.com and return and array of three parts www yourdomain.com yourdomain

in javascript I use it like this: var reDomainName = /^(.?).?(([^.])(?:(?:..{2,3})|(?:(?:..{2,3})(?:..{2}))))$/; var aDomainName = sDomain.match( reDomainName ) || ["","",""];

Submitted by Quincy Acklen - 8 years ago