K
K
konservat0r2018-03-30 14:58:03
Regular Expressions
konservat0r, 2018-03-30 14:58:03

How to remove 8 characters from a link using a regular expression?

I wanted to give links as in this example
to wp-content/uploads/2010/10/DSC_0331z-300×201.jpg
after wp-content/uploads/2010/10/DSC_0331z.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tallmange, 2018-03-30
@konservat0r

<?php

$pattern = "(-\d+x\d+(?=\.(?:jpg|jpeg|png)))";
$subject = "wp-content/uploads/2010/10/DSC_0331z-300x201.jpg wp-content/uploads/2010/10/DSC_ff0331-1920x1080.png";
$replace = "";

echo preg_replace($pattern, $replace, $subject);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question