简体   繁体   中英

Regex to match all URLs containing a specific word

I'm looking for a regex to match all URLs containing a specific word eg "linux" anywhere within the URL.

.*linux.* seems to work with URLs with the word in the subdomain, domain and TLD, but it doesn't find URLs containing the word within the path, eg www.blabla.com/blalinuxbla.html

From java.util.regex.Pattern :

Pattern p = Pattern.compile(".*linux.*");
Matcher m = p.matcher(url);
boolean b = m.matches(); // returns true

甚至更简单

url.toString().contains("linux");// returns true

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