3

I am facing issue when trying to extract specific value from the string but not getting the proper output.

$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]

I want the value inside name= till the comma and I tried with preg_match_all but it just gives the first word.

This is what I tried:

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

Please help

Thanks

Rwd
  • 34,180
  • 6
  • 64
  • 78
Dython
  • 134
  • 4
  • 12

2 Answers2

5

there are multiple approaches , available on whether preg_match or preg_match_all

$results = preg_match('#name=(.*?),#', $matches);

OR

$results = preg_match('#name=([^,]+),#', $matches);
hassan
  • 7,812
  • 2
  • 25
  • 36
5

You could try something like:

preg_match("/name=(.+?),/", $string, $matches);
$result = end($matches);

Hope this helps!

Rwd
  • 34,180
  • 6
  • 64
  • 78