首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

帮忙改上正则表达式. 多谢

2012-09-10 
帮忙改下正则表达式. 谢谢public static void main(String[] args){String str http://localhost:8080/

帮忙改下正则表达式. 谢谢
public static void main(String[] args)
  {

  String str = "http://localhost:8080/sshframework/param/queryParamData.action?vpar=2012-8-17-10-26-16-0.40798535273884656&status=&pageNo=1&dtsNo=&versionNo=&pageSize=10&dateEnd=&dateBegin=&applyPerson=&paramType=&";
  String str1 = "http://localhost:8080/sshframework/param/queryParamData.action?";
  String reg = "/(\\w+)(/\\w+)(\\.action)(\\?vpar)";
  Pattern p = Pattern.compile(reg);
  Matcher mt = p.matcher(str);
  Matcher m = p.matcher(str1);
  String nameSpace = "";
  if (mt.find())
  {
  nameSpace = mt.group(1);
  }
  System.out.println(nameSpace);
   
  if (m.find())
  {
  System.out.println(m.group(1));  
  }
   
  }

上面是 我改进的一个正则表达式,但是达不到要求、

 我需求是:
 当有.action?vpar的时候 不取param这个字符串,并且返回为空字符串。
当只有.action的时候取param 。 并且返回这个字符串。

[解决办法]

Java code
    public static void main(String[] args) {        String str = "http://localhost:8080/sshframework/param/queryParamData.action?vpar=2012-8-17-10-26-16-0.40798535273884656&status=&pageNo=1&dtsNo=&versionNo=&pageSize=10&dateEnd=&dateBegin=&applyPerson=&paramType=&";        String str1 = "http://localhost:8080/sshframework/param/queryParamData.action?";        String reg = "/(\\w+)(/\\w+)(\\.action\\?)$";        Pattern p = Pattern.compile(reg);        Matcher mt = p.matcher(str);        Matcher m = p.matcher(str1);        String nameSpace = "";        if (mt.find()) {            nameSpace = mt.group(1);        }        System.out.println(nameSpace);        if (m.find()) {            System.out.println(m.group(1));        }    }
[解决办法]
探讨

引用:
引用:
public static void main(String[] args)
{

String str = "http://localhost:8080/sshframework/param/queryParamData.action?vpar=2012-8-17-10-26-16-0.40798535273884656&……

热点排行