本帖最后由 ZhMilo 于 2009-08-07 11:07:58 编辑

解决方案 »

  1.   

    如果2两边的字母要限制长度的话
    [a-zA-Z]{n,m}2[a-zA-Z]{n,m}
    其中n为最少多少位,m为最多多少位
    建议去看下api,上面很详细
      

  2.   

    火龙果写的一个正则教程上有一个小小的测试工具,代码如下:
    import java.io.Console;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;public class RegexTestHarness {    public static void main(String[] args) {
            Console console = System.console();
            if (console == null) {
                System.err.println("No console.");
                System.exit(1);
            }
          
            while (true) {
                Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "));
                Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: "));
                boolean found = false;
                while (matcher.find()) {
                    console.format("I found the text \"%s\" starting at index %d " +
                            "and ending at index %d.%n",
                            matcher.group(), matcher.start(), matcher.end());
                    found = true;
                }
                if (!found) {
                    console.format("No match found.%n");
                }
            }
        }
    }
      

  3.   

    这个教程的下载地址是:http://download.csdn.net/source/370958 教程里有其它版本的测试工具。
      

  4.   


    String regStr = "\w+2\w+";
      

  5.   


    兄弟,你这个怕是不行.其一,"\\w+2\\w+"这样才是正则.
    其二,\\w包含了数字字符了.