tags:

views:

89

answers:

2

Through the code i got the output content as XML. I have pair or multiple of html tags as follows:

December 10

Welcome to this space

Hai, Today is Tuesday

This a xml tag

I want a regular expression as below requirement:

As above mentioned i want only one EMPTY pair Tag as

. I do not want the repeated EMPTY indefinite or definite pair tags.

Please help me in this regard to use regular expression to overcome the issue.

+1  A: 

The question mark makes the expression non-greedy, so that only the contents between two tags are matched, instead of the contents between the very first opening and the very last closing tag. This is assuming you don't have nested p tags, else you're going to be in trouble with this one...

/<p>(.*?)<\/p>/

Obviously, you're going to have to go with something like preg_match_all in PHP, depending on which language you use. You're going to find the contents of the tag in the first matching group.

Franz
You don’t need to escape the `<` and `>`.
Gumbo
Thank you. Wasn't sure about this because of named capturing groups etc.
Franz
+1  A: 

What if you have nested p blocks. Again the same mistake parsing HTML codes with the Regex, DOM is used to parse HTML and not Regex. Parsing Html The Cthulhu Way

Priyank Bolia