0

I want to match n number of characters between a "<" and ">" characters. For example, I want to be able to match <a href = "image1.jpg"> or <a href = " http://www.learnmore.com/&gt; essentially with the same pattern. This is because, the strings I receive might have n number of characters between the special characters. Once I match the pattern which includes the special characters, I will replace it with a blank space(which I am able to do currently---the replacing part.). I need help with the matching part only.

Raghu
  • 1,091
  • 4
  • 20
  • 38

3 Answers3

1

Obligatory "don't try to parse HTML with regex" link

Community
  • 1
  • 1
Phil Miller
  • 34,402
  • 11
  • 64
  • 88
0

You can try the following regular expression

(&lt;|<)(.*?)(&gt;|>)

to match against your string (assuming the &gt; was not a formatting error in your question but the actual content in the string).

Howard
  • 37,615
  • 8
  • 61
  • 82
  • I am trying to replace HTML tags with a blank space. If I hard code the HTML tag, I can replace and get the tag, but I am trying to match any tag and so the question on the forum. @Howard, I tried your expression, but it did not work. The > was a formatting error. It should be < or >. – Raghu Jul 14 '11 at 19:04
0

First replace &gt; with > and &lt; with <. Then do your pattern matching as usual using regex or whatever.

tskuzzy
  • 34,979
  • 14
  • 68
  • 136