Answer the question
In order to leave comments, you need to log in
How to capture a string with a regular expression?
Good evening!
Tell me how to write a regular expression in order to select the first string from a set of substrings:
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w1920h520mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w225h124mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w280h160mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w600h450mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w730h340mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w820h410mc.jpg
files/9/6/7/b/f/f7ba4cbf32ff8971b352e3fc2ac.jpg
files/9/6/7/b/f/f7ba4cbf32ff8971b352e3fc2ac.jpg.w730h350mc.jpg
files/e/b/1/e/1/05c09ea7a96cf55071450839570.jpg
files/e/b/1/e/1/05c09ea7a96cf55071450839570.jpg.w730h350mc.jpg
files/e/d/2/f/8/7ca3d9a5390be989ca44c8f5d58.jpg
files/e/d/2/f/8/7ca3d9a5390be989ca44c8f5d58.jpg.w730h350mc.jpg
Answer the question
In order to leave comments, you need to log in
$file = <<<EOT
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w1920h520mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w225h124mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w280h160mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w600h450mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w730h340mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w820h410mc.jpg
files/9/6/7/b/f/f7ba4cbf32ff8971b352e3fc2ac.jpg
files/9/6/7/b/f/f7ba4cbf32ff8971b352e3fc2ac.jpg.w730h350mc.jpg
files/e/b/1/e/1/05c09ea7a96cf55071450839570.jpg
files/e/b/1/e/1/05c09ea7a96cf55071450839570.jpg.w730h350mc.jpg
files/e/d/2/f/8/7ca3d9a5390be989ca44c8f5d58.jpg
files/e/d/2/f/8/7ca3d9a5390be989ca44c8f5d58.jpg.w730h350mc.jpg
EOT;
preg_match('/^.*?\.jpg/', $file, $m);
echo $m[0]; //files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question