Consider the code below, why it is not working?
<?php
$str = "
<h4>
title
</h4>
";
$result = preg_match_all ('/<h4>([\d\D])<\/h4>/mi', $str, $matches);
var_dump($matches);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You probably meant
The regex you applied,
'/<h4>([\d\D])<\/h4>/mi', means “Match an opening h4, one character that’s either a digit or not a digit, and a closing h4.” But you have plenty of characters to match, so you need to specify a quantifier (“more than one”,+). Update: you need a non-greedy quantifier,+?, if you have more than one h4 (very likely!) And the class[\d\D]can be reduced to “any character”,.. One more point: you need to use/sinstead of/mto get the behaviour you want.This will probably include the newlines in your match!