PHP preg_match搜索特定模式

I am not familiar with the syntax of preg_match and want to find following pattern within a string.

  • The substring must start with M or L (M|L + white space)

  • It ends with an white space

  • between that there is a number, separated by a , and both sides of the , the length of the number is 1-3 character

Can somebody help me with that?

example-string:

<path d="M 584,363 L 584,364 L 582,365 />
preg_match_all( '~[ML]\s+[0-9]{1,3},[0-9]{1,3}~i', $str, $mats );
print_r( $mats );

The i flag after the regEx means case insensitive, change that if desired.

How about preg_match_all:

preg_match_all('/(\b[ML]\s+\d{1,3},\d{1,3}\s+)/', $string, $match);