Reputation: 6749
Hi i am having an issue in trying to extract variables using preg replace .I guess i am messing with the delimiters or just doing it wrong
Subject
'file': 'EoWviKqVizQ,end=1384596943/data=B262F941/speed=375k/2305873_hd.flv',
I need to extract
end=1384596943/data=B262F941/speed=375k/1234_hd.flv
This is basically the string after the comma in between the single quotes.
My attempts
preg_match('#'file':'(.*)'#',$input , $matches)
preg_match("#'file':'(.*)'#",$input , $matches)
Hope someone can help me out
Regards
Upvotes: 0
Views: 59
Reputation: 44851
Just do this:
$input = "'file': 'EoWviKqVizQ,end=1384596943/data=B262F941/speed=375k/2305873_hd.flv',";
$mypart = preg_replace("/^'file': '[^,]+,/", "", $input); // strip first part, i.e., "'file': 'EoWviKqVizQ,"
$mypart = preg_replace("/',\s*$/", "", $mypart); // strip last part, i.e., "',"
echo $mypart;
EDITED based on OP feedback (replaced initial [^']+
with file
to match only lines starting with 'file'
, etc.
Upvotes: 1