rgomes
rgomes

Reputation: 221

Get Integer between parenthesis using RegExp

I'm trying to use regExp to get values between parenthesis: for example:

<td width=40><input type=\"button\" OnClick='FullScreen(1)' value=\" 1\" size=80></td>
<td width=(40)><input type=\"button\" OnClick='FullScreen(2)' value=\" 1\" size=80></td>
<td width=40><input type=\"button\" OnClick='FullScreen(3)' value=\" 1\" size=80></td>
<td width=40><input type=\"button\" OnClick='FullScreen(4)' value=\" 1\" size=80></td>

I want to retrieve the values of the Fullscreen in this case 1,2,3 and 4

I try this regular expression:

    Pattern p = Pattern.compile("\\((.*?)\\)");

    Matcher m = p.matcher(String);
    if(m.find()){
        System.out.println("val = " +m.group(1));
    }

but this retrieves all the values between parenthesis how to I make to only get the values from the FullScreen string?

Thanks

Upvotes: 1

Views: 135

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Also add the FullScreen prefix to your regex.

Pattern p = Pattern.compile("FullScreen\\((.*?)\\)");
Matcher m = p.matcher(String);
if(m.find()){
    System.out.println("val = " +m.group(1));
}

Upvotes: 3

Related Questions