0

How can i use regex to get the following. the matter within the tags might be alphabets,numbers & meta characters.

Input Srting : "<p>Hi </p><p>there</p>"

Expected output: "Hi<p>there</p>.

Julien Breuil
  • 165
  • 1
  • 2
  • 15
Fusion
  • 165
  • 2
  • 8
  • 5
    What are the rules? Remove first `

    `? Remove first tag? Remove all tags but not the last one? Remove any tag that contains at least one whitespace? Do the tags can contain attributes (e.g. `style=""`)?
    – sp00m Jun 13 '12 at 12:30
  • 1
    Unless it's super simple and trivial, do not use regex to parse HTML. Try a HTML parser instead. – Bala R Jun 13 '12 at 12:34
  • Agree with Bala, unless looking for a particular tag, don't use regex -- it can be quite daunting to do so. If you are just looking to remove white space before the closing tag, then that is pretty simple. – Feuerwehrmann Jun 13 '12 at 12:36
  • 2
    [It reminds me something...](http://stackoverflow.com/a/1732454/1225328) – sp00m Jun 13 '12 at 12:36

1 Answers1

0

Until futher specs arrive, use the following:

<p>(.)*?</p> and use the first (and only) group (.)*?

This matches <p> Hi </p> then use \1 to refference ' Hi '

IDKFA
  • 436
  • 3
  • 5