简体   繁体   中英

How to get multiple urls http and https using regular expressions?

http:\/\/embed.(.*).com\/\?id=([0-9]+)

$userAgent  = array('http' => array('user_agent' => 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D)'));

is there anyway to get both http and https with the above code?

Add an optional pattern s? ( s will match an s and ? will make the regex engine match it one or zero times):

https?:\/\/embed\.(.*)\.com\/\?id=([0-9]+)
    ^^ 

I also think you forgot to escape the dots after embed and before com . You also might want to replace (.*) with ([^\\/]*) to avoid overflowing across / separated URL sections, so consider using

https?:\/\/embed\.([^\/]*)\.com\/\?id=([0-9]+)

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