Php regular expression matching problem! $ Str = < The theory
My myselef
Your yourselef
STR;
$ Reg = '/^ ([a-zA-Z] +) \ s * \ 1 [a-zA-Z] * $/M ';
Preg_match_all ($ reg, $ str, $ result );
Var_dump ($ result );
?>
The following is the matching result. I don't quite understand why only the last one is matched?
Array (2) {[0] => array (1) {[0] => string (14) "your yourselef"} [1] => array (1) {[0] => string (4) "your "}}
Reply to discussion (solution)
$ Str = <
Array( [0] => Array ( [0] => the theory [1] => my myselef [2] => your yourselef ) [1] => Array ( [0] => the [1] => my [2] => your ))
In windows, the line feed is \ r \ n
Change your target string and consider it carefully:
$str = "the theory\nmy myselef\nyour yourselef";
In windows, the line feed is \ r \ n
+ 1
$ Match before \ n or the end of a string./r is also a character and is not in the range of [a-zA-Z], but the last line is the end of a string.
Then the last line $ str = <
The theory
My myselef
Your yourselef
STR; is there a line feed problem? is there/r/n? I don't quite understand
$ Str = <
There is no line break behind the last line of data
$ Str = <
The last line of data is followed by a line break.
Thank you! Taught!