A
A
Anatoly2017-10-28 19:17:41
code review
Anatoly, 2017-10-28 19:17:41

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

2 answer(s)
B
BATPYIIIKOB, 2019-11-28
@BATPYIIIKOB

Check out the layout:
5de013c62cbff038213481.png

S
spike__x, 2017-10-28
@les-anatoliy

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

Ask a Question

731 491 924 answers to any question