I know this is a very simple question but since I am very bad in regex , have to ask below question. I want to write a regex expression in java which will match below two url patterns given :
{contextPath}/javax.faces.resource/**
{contextPath}/rfRes/**
The url will be read from http request object and will be compared using java pattern object like below :
Pattern p = //regex here ;
p.matcher(r.getRequestURL().toString()).matches();
Can anybody help me in writing a regex experion for above two urls ?
you can use this :
.*?(?:\/javax\.faces\.resource\/|\/rfRes\/).*$
demo here : http://regex101.com/r/rV5mR8/2
It checks whether the string start with either of the two options which you want.
您可以使用此:
boolean matches = r.getRequestURI().matches(".*?/(javax\.faces\.resource|rfRes)/.*");
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.