Regex to match all HTML tags contains <p> and </p>
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 rep开发者_StackOverfloweated EMPTY indefinite or definite pair tags.Please help me in this regard to use regular expression to overcome the issue.
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.
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
精彩评论