0

Trying to get the result of an html:

private static final String PATTERN = "(ReportSession=)[0-9A-Za-z]{24}";`

...    

Pattern pattern = Pattern.compile(PATTERN);
Matcher matcher = pattern.matcher(".axd?ReportSession=frytm055l51aigbigh5xzrin\u");
if(matcher.find()){
    textView1.setText(matcher.group(1));
}

The output is ReportSession= but I need to get the whole ReportSession=frytm055l51aigbigh5xzrin before the backslash. Any ideas?

2 Answers 2

3

You denote groups with parentheses. You have only one inner group, that being (ReportSession=). If you need the whole pattern you can use:

matcher.group();

or

matcher.group(0);

Group zero denotes the entire pattern, so the expression m.group(0) is equivalent to m.group().
Source: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/regex/Matcher.html#group%28int%29

Sign up to request clarification or add additional context in comments.

Comments

1

Use matcher.group(0) instead of matcher.group(1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.