php - 如何从字符串中获取特定值

Dyt*_*hon 3 php string preg-match-all

我在尝试从字符串中提取特定值但未获得正确输出时遇到问题.

$string = com.xyz.ghop.service.sprint.Sprint@1b0258c[id=257,rapidViewId=94,state=CLOSED,name=Alert Success 5,goal=,startDate=2016-08-16T20:20:46.730+05:30,endDate=2016-08-26T20:20:00.000+05:30,completeDate=2016-08-26T21:18:53.928+05:30,sequence=257]
Run Code Online (Sandbox Code Playgroud)

我希望name =中的值直到逗号,我尝试使用preg_match_all,但它只是给出了第一个单词.

这是我试过的:

preg_match_all("/(?=name\=([^\W]+))/", $string, $matches); 
$resulte = implode(",", $matches[1]); 
Run Code Online (Sandbox Code Playgroud)

请帮忙

谢谢

has*_*san 5

有多种方法,可用于preg_match还是preg_match_all

$results = preg_match('#name=(.*?),#', $matches);
Run Code Online (Sandbox Code Playgroud)

要么

$results = preg_match('#name=([^,]+),#', $matches);
Run Code Online (Sandbox Code Playgroud)


Rwd*_*Rwd 5

你可以尝试类似的东西:

preg_match("/name=(.+?),/", $string, $matches);
$result = end($matches);
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!