I have the following sample set of data:
<p>first line\n
second line\n
third line\n</p>
first line\n
second line\n
third line\n
Using regex, how could I match on the newline characters, but only when they are within the paragraph tags.
This code would be used within php.
You could split this in two regex’s. First split on your
<p>tags (<p>.*?</p>) , then match on newline from the result.Divide and conquer. Several small regex’s will often perform faster than huge ones.
I assume you have total control over the html and know it’s well formed. Because using regex on html is a no-no in most cases. Use a DOM parser instead.