Eclipse" String变量无法解析为变量"

时间:2017-11-28 11:13:18

标签: java

这是代码,str2Check无法超出范围。

public static void regexChecker(String theRegex, String str2Check)
    {
        //defining the regex pattern

        Pattern checkRegex = Pattern.compile(theRegex);

        // Creating a Matcher object that searches the string for anything that
        //matches the REGEX

        Matcher regexMatcher = checkRegex.matcher(str2Check); //error here

        while (regexMatcher.find())
        {   
            System.out.println(regexMatcher.group());
            System.out.println("Start Index: " + regexMatcher.start());
            System.out.println("End Index: " +  regexMatcher.end());
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        String longString = " Derek Banas CA 12345 PA (412)555-1212 johnsmith@hotmail.com 412-555-1234 412 555-1234 "; 
        String strangeString = " 1Z aaa **** *** {{{ {{ { ";

        regexChecker("\\s[A-Za-z]{2,20}",longString);

    }

请帮忙。挠挠脑袋......根本无法理解它。

0 个答案:

没有答案