\将下一个字符标记为一个特殊字符、或一个原义字符、或一个 后向引用、或一个八进制转义符。例如,'n' 匹配字符 "n"。'\n' 匹配一个换行符。序列 '\\' 匹配 "\" 而 "\(" 则匹配 "("。

解决方案 »

  1.   

    smallbird105(快乐鸟) 
    我看法跟你相同,但我使用字串\13579去匹配,就是匹配不成功。我的测试代码如下:
    package com.test;
    import gnu.regexp.RE;
    /**
     * <p>Title: game</p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * @author water
     * @version 1.0
     */public class test {  public test() {
      }
      public static void main(String[] args) {
        test test1 = new test();
        String line = "\130200";
        RE extractMSISDN = null;
        try {
          extractMSISDN = new RE("^\\+[-\\d]*");
          Object MSISDN = extractMSISDN.getMatch(line);
          System.out.println("=="+MSISDN+"==");
        }
        catch (REException ex) {
        }
      }
    }如果方便我们可以QQ当中交流。欢迎加入3953507或者email:[email protected]
      

  2.   

    楼上的String line = "\130200";错了
    应该是String line = "\\130200";
      

  3.   

    wolfsquare(狼平方) 说得是对的。
      

  4.   

    wolfsquare(狼平方) :不会吧,+表示一个或多个,所以一个或两个是无所谓的啦。
    何况,我加了两个测试也不行啊,返回一律的null.
      

  5.   

    给你一个最简单的测试方法:
    <html>
    <head>
    </head>
    <script>
      var re = /^\\+[-\\d]*/;
      var str = "\\\\\\";
      if(re.test(str))
      {
        alert("success!");
      }
      else
      {
        alert("failed");
      }
    </script>
    <body>
    </body>
    </html>
      

  6.   

    smallbird105(快乐鸟) :在HTML当中没问题,但在JAVA当中不行。郁闷中……
      

  7.   

    To water_qing(小清) 
    匹配字符串的前面两个\\我这样理解的,要被匹配的字符串必须以\开头,但在字符串中则\\才代表一个\,否则就会转义为别的字符了。
      

  8.   

    To water_qing(小清) 请你给我gnu这个包,我帮你测试一下如何?
      

  9.   

    String str = "\\130200";
    //   pattern = Pattern.compile("^\\\\+[\\-\\d]*");
       extractMSISDN = new RE("^\\\\+[\\-\\d]*");那么你用这个吧,应该可以的
    我用regex测试过了
      

  10.   

    XKP(低等下人) :那样的话就修改了原来的意思了。
      

  11.   

    各位,终于解决了!
    感谢各位积极参与。
    匹配字串:+130200
    ^\\+[-\\d]*
    ^\\+是指以+开始的字串
    因为+也是保留字符,前面需要进行转义,而在JAVA当中是两个\\进行的。