-2

i have this regex:

/\<p(.+?|)>(.+?)<\/p\>/ims

which matches all the <p> inside an .html doc. However sometimes the <p> has attributes (like class, style, id etc.. ) and sometimes it doesn't.

The problem with this regex is if the <p> has no attributes it matches the closing tag of the.

here is an example:

https://regex101.com/r/jX5kS3/1

Izopi4a
  • 490
  • 3
  • 18
  • 1
    Please see [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/q/3577641/476) [**Regex is not the way to parse HTML.**](http://stackoverflow.com/a/1732454/476) – deceze Oct 06 '15 at 07:17
  • Are you sure????????// https://regex101.com/r/cJ6zQ3/10 – vks Oct 06 '15 at 07:18
  • https://regex101.com/r/jX5kS3/1 – Izopi4a Oct 06 '15 at 07:20

1 Answers1

0

What about

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

https://regex101.com/r/pR0iB2/1

Amarnasan
  • 14,939
  • 5
  • 33
  • 37