简体   繁体   中英

Regex java predefined number of slash in url

I have a url string as theese http://www.domain.it/aaa/007585100-5/aaa.html or http://aaa.domain.it/aaa/aaa/aaa.html

with this regex java ^.*(domain.it).*(.html){1}$ i match the second url but not the first. In addition my regex is not accurate.

Can also divide the regex in two regex separated. The one or two regex must exclude from match the url like aaa.domain.it/

PS the string "aaa" in url's can be a random string composed by 1..N char [a-z0-9].

Thanks in advance

Try this:

"^http://[0-9a-zA-Z]+\\.domain\.it(/[^/]+?){3}.html$"

3 slashes max, and exclude *.domain.it/ :

"^http://[0-9a-zA-Z]+\\.domain\.it(/[^/]+?){1,3}.html$"

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