简体   繁体   中英

Javascript Regex: How to detect if a url is of the form http://<any string without a dot>.one.two.com?

How can I use regex in a JavaScript function to return true if the url is of the form:

http://<any string without a dot>.one.two.com

and false otherwise?

for example it would return true for the following:

http://helloworld.one.two.com , http://poop.one.two.com , etc.

for example, it would return false for

http://rawr.zero.one.two.com , http://two.com , etc.

Thanks!

/^http:\\/\\/[^.]*\\.one\\.two\\.com$/

/^http:\/\/[^.]+\.one\.two\.com/
/^http:\/\/[^\.]+\.one\.two\.com$/

末尾的$是指示性的,否则http://something.one.two.com.blah也将匹配。

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