0

I have a regular expression that should capture 4 elements but it is only capturing 3. Here is the code

<?php

$re = '/<input.+>(.*)</m';
$str = '    <input type="radio" name="562" value="1" onclick> turtle.show() <br>
<input type="radio" name="562" value="2"> turtle.showLocation() <br>
<input type="radio" name="562" value="3"> turtle.showDirection()  <br>
<input type="radio" name="562" value="4"> turtle.showturtle() <br><input type="hidden" id="ans562" value="4">';

preg_match_all($re, $str, $matches);

// Print the entire match result
var_dump($matches);

https://3v4l.org/YY20a

u_mulder
  • 54,101
  • 5
  • 48
  • 64
NeDark
  • 1,212
  • 7
  • 23
  • 36

1 Answers1

0

Try with this regular expression - in lazy/ungreedy mode:

$re = '/<input(?:\s.*)?>([^<]*)</mU';
IVO GELOV
  • 13,496
  • 1
  • 17
  • 26