日期:2014-05-20 浏览次数:20735 次
String regex = "/(news|finance)/.*[?&]from=ucweb([&#].*|$)"; System.out.println("/news/abroad/zhuanti?nid=122334&from=ucweb&foo=sthelse".matches(regex)); System.out.println("/news/?from=ucweb&foo=sthelse".matches(regex)); System.out.println("/news/abroad/zhuanti?nid=122334&from=ucweb".matches(regex)); System.out.println("/news/abroad/zhuanti?nid=122334&from=ucweb#anchor".matches(regex)); System.out.println("/news/abroad/zhuanti?nid=122334&xfrom=ucwebtt".matches(regex)); System.out.println("/news/abroad/zhuanti?nid=122334&xfrom=ucweb".matches(regex)); System.out.println("/news/abroad/zhuanti?nid=122334&from=ucwebtt".matches(regex)); System.out.println("/news/abroad/zhuanti?xfrom=ucweb".matches(regex)); System.out.println("/news/abroad/zhuanti?from=ucwebtt".matches(regex));
------解决方案--------------------
是匹配(/news/|/finace/)&from=ucweb,即/news或/finace后面紧跟/&from=cuweb,还是说以/news/或/finace/开头,中间可以出现任意abroad/zhuanti,然后跟着&from=cuweb,随后任意,即&foo=sthelse可有可无
have a try
String regex = "/(news|finance)/.*?[&]from=ucweb([&].*)?";
------解决方案--------------------
这个需用正则表达式。但是描述的不是很到位啊。
------解决方案--------------------