-4

I'm trying to develop a regular expression for matching fixed characters. Below is the example:

String test = "<P>This is test. <A HREF="www.google.com">Google</A></P><P>Again this is a test. <A HREF="www.facebook.com">Facebook</A></P>";

I want to replace the block, having content starting with <A HREF= and ending with >, with the empty space. Can anyone tell me the regex for the same?

Output should be: <P>This is test. Google</A></P><P>Again this is a test. Facebook</A></P>

Edit: Some people are trying to relate this question to the one which specifies about regex and XHTML parsing. Well, I'm trying to match a block of characters in a java. So it clearly has not any relation with the XHTML parsing.

Ambar Dudhane
  • 37
  • 1
  • 6
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Zenoo Aug 09 '18 at 07:39
  • You can use this answer as a reference - https://stackoverflow.com/questions/8758653/regular-expression-to-remove-a-substring-between-two-characters – Prashant Aug 09 '18 at 07:39
  • 1
    What have you tried, Stack overflow is a place to ask and answer questions. Not somewhere to get people to do your work for free. – JGNI Aug 09 '18 at 07:40

1 Answers1

0

You can capture those strings with <A.+?> and replace them with empty strings. The ? here ensures non-greedy matching.

Sufian Latif
  • 13,086
  • 3
  • 33
  • 70