楼上的就可以了
这个不用regex反而更方便且更快吧,比如考虑startsWith,或者trim().equals(), 当然,这个不是100%符合你的要求

解决方案 »

  1.   

    记得给分啊!!!
    String simple = "Strddd ";
    Pattern pp = Pattern.compile("^Str.*[\\t\\s]$");
    Matcher mm = pp.matcher(simple);
    if(mm.matches()){
    System.out.println("OK");
    }
    else{
    System.out.println("Sorry");
    }
      

  2.   

    不好意思,可能我的描述不清。这么说String s = "endStr asdf String   Str   sadfasd"
    类似于上述文本中把第一个和第三个Str匹配。而第二个Str因为后面不是空格或者tab空,所以不作判断。我写了一个"Str[\\s+]",这样就应该搞定了,现在是我要获得第一个Str的位置,用。start()方法就行,那么下面我就要循环下去,获得符合条件的第二个Str,请问怎么作,用什么方法?
      

  3.   

    采用Jakarta-ORO(http://jakarta.apache.org)
    示例代码如下:
    import org.apache.oro.text.regex.*PatternMatcher matcher;
    PatternCompiler compiler;
    Pattern pattern;
    PatternMatcherInput input;
    MatchResult result;compiler = new Perl5Compiler();
    matcher  = new Perl5Matcher();somePatternString = "Str\\s+";
    someStringInput = "endStr asdf String   Str   sadfasd";try {
       pattern = compiler.compile(somePatternString);
     } catch(MalformedPatternException e) {
       System.out.println("Bad pattern.");
       System.out.println(e.getMessage());
       return;
     }input   = new PatternMatcherInput(someStringInput);//多次匹配
    while(matcher.contains(input, pattern)) {
       result = matcher.getMatch();  
       System.out.println(result.toString());
       //添加需要处理的代码
     }输出结果:
    Str(第一个)
    Str(第三个)