Hey guys, question about regex in PHP!
For the given pattern, kinda like a shell terminal syntax:
application>function -arg1 value -arg2 value -arg3 value -arg4 value
I want to parse the arguments. This is my regex code
$command=' -arg1 value -arg2 value -arg3 value -arg4 value ';
// note the string begins by a space character and ends by a space character
// now i'm trying to parse arguments
$cmd->arguments=new \stdClass();
preg_replace('`\s-(.*)\s([a-zA-Z0-9-_]*)\s`Ue',
'$cmd->arguments->$1="$2";',$command);
// this regex will pick one matching out of two and returns
$cmd->arguments=stdClass(
[arg1]=>value,
[arg3]=>value
)
arg2 and arg4 are skipped. Any idea why? Thanks in advance!