简体   繁体   中英

Regular Expression Pattern (match URL)

I need a regular expression that identify special links.

I have an array with links, for example this one

array[1] = "http://domain.com/dfdf"
array[2] = "http://domain.com/dfgf"
array[3] = "http://domain2.com/derf"

I want to use a regular expression that extract links from this array under a specific domain (for example domain2)

I'll get an array

array[1] = "http://domain2.com/derf"

I'm looking for the pattern only (I use PHP)

This regular expression should do it:

^http://domain2\.com/

And converted into PCRE with / as delimiter:

/^http:\/\/domain2\.com\//

But you can use another character if you want:

~^http://domain2\.com/~

怎么样:

(?<!")http://domain2.com[^"]+

这将匹配https以及http链接:

#^https?://domain2\.com/#

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM