user3872094 user3872094 - 1 year ago 66
Java Question

Unable to know how to use the substitution

I've a string like below

<a name="1.F"></a>

I'm trying to extract only the value name value. And the regex I'm using to get this done is.

Search string

<a name=\"(\d)+(\.)(\w)+\"?>

Replace String


Result: Here the Result that I get is what is in between **

search result :

**<a name="1.F">**</a>

Current Replace Result:


Expected Replace Result:


please let me know, how can we get the Expected result.


Answer Source

I think you should change it to

<a name=\"(\d)+(\.)([^"]+)\"?>

replace (\w) by ([^"]) .

    String s = "**<a name=\"1.F\">**</a>";
    Pattern p = Pattern.compile("<a name=\\\"(\\d)+(\\.)([^\"]+)\\\"?>");
    Matcher m = p.matcher(s);
    while (m.find()) {
        System.out.println( + +;

=>> 1.F

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download