I want to write a regular expression to find the word after $body->
That is userId
, deviceId
, deviceToken
and deviceType
in the following code sample:
function deviceUpdate($body)
{
$userId=trim($body -> userId);
$deviceId= $body -> deviceId;
$deviceToken=trim($body -> deviceToken);
$deviceType=trim($body -> deviceType);
}
There can be a single space or multiple spaces after body keyword and after ->
The regular expression I tried is:
(?<=body ->\s)\S+
But this does not work properly if there is no space between body
and ->
.
Edit : I used the the regular expression ~function\s*(.+?)(~ to find the name of function ( deviceupdate) and ~\$body\s*->\s*(\w+)~ to find all keywords after body -> operator. It works perfectly fine. Suppose, i have 2 functions :
function deviceUpdate($body)
{
$userId=trim($body -> userId);
$deviceId= $body -> deviceId;
}
function postad($body)
{
$adtitle = $body -> adtitle;
$addescription = $body -> addescription;
}
How to extract the function 1 name that is deviceUpdate and corresponding keywords in that same function after body -> that is ( userId,deviceId) in one array and function 2 name postad and corresponding keywords in that same function after body -> that is ( adtitle,addescription) in second array?
Currently when i use preg_match_all and regular expression as stated above it returns everything it matches in a single array.