Replacing link tag using regex

Total Post:30


 1491  View(s)
Rate this:

I'm using java. And i want to find then replace hyperlink and anchor text of tag <a> html. I knew i must use: replace() method but i'm pretty bad about regex. An example:

<a href="">anchor text 1</a>

will be replaced by:

<a href="">anchor text 2</a>

Could you show my the regex for that purpose?

Thanks a lot.

  1. Re: Replacing link tag using regex

    You could perhaps use a replaceAll with the regex:

    <a href=\"[^\"]+\">[^<]+</a>

    And replace with:

    <a href=\"\">anchor text 2</a>

    [^\"]+ and [^<]+ are negated  class and will match all characters except " and < respectively.

      Modified On Apr-03-2018 04:44:00 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.