-2
<div class="hello">

<span>Hello World<span>

<div>

I need to get all content inside the div.

I tried this way, but I can not get:

regex101 screenshot

chris85
  • 23,846
  • 7
  • 34
  • 51
  • 2
    https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php – AbraCadaver Oct 03 '17 at 17:05
  • You wouldn't use a hammer to drill holes into wood. Why use regex to parse XML? But anyway, to answer your question `.` matches any character *except newline characters*. Use the `s` modifier – ctwheels Oct 03 '17 at 17:06
  • In the future use the `save regex` option and provide the link... and preferably the code here as well. – chris85 Oct 03 '17 at 17:12
  • @douglas I bet you are not using single line flag. Do you? – Federico Piazza Oct 03 '17 at 17:22

1 Answers1

0

Use the following:

/(<div class="hello">){1}(.)*(<\/div>){1}/is

The 's' flag allows the dot (.) to match newline. Then you will get the three groupings that you desire.

See https://regex101.com/r/dlrbhM/2 for a live example

jhenderson2099
  • 956
  • 8
  • 17