preg_match_all - > string:var a = 100 [关闭]

I'm trying parse string:

var a = 100
var b = 150
var c = test

I was trying create regex:

preg_match_all('/var( )*=( )*([^\s]+)/', $code, $get_zmienne);
preg_match_all('/var(\s)*=(\s)*([^\s]+)/', $code, $get_zmienne);

and this is wrong.

Have a try with:

preg_match_all('/var\s*(\w+)=\s*(\S+)/', $code, $get_zmienne);

This will match:
var: litteral var
\s*: 0 or more white spaces
=: litteral =
(\w+): group1 that contains one or more word characters ie:[a-zA-Z0-9_]
\S+: one or more non space character.