K
K
Kornely2021-11-17 12:09:43
PHP
Kornely, 2021-11-17 12:09:43

How to replace a lower case in a regular expression without touching the corresponding capital?

There is this code:

if (условие) $i = preg_replace('/https:\/\/site.com\/([^\s]*)a.jpg/U','https://site.com/$1b.jpg',$i);

As you can see, with a certain if, the letter a at the end of the file name is changed to the letter b .

The problem is that the capital letter also changes if it is at the end of the file - A . But this cannot be allowed.

How can I make a letter change only if it is lowercase?

Thanks in advance to all who answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-11-17
@Korneliy

This is how it works by default.

print preg_replace('/https:\/\/site.com\/([^\s]*)a.jpg/U','https://site.com/$1b.jpg', 'https://site.com/testa.jpg');
// https://site.com/testb.jpg

print preg_replace('/https:\/\/site.com\/([^\s]*)a.jpg/U','https://site.com/$1b.jpg', 'https://site.com/testA.jpg');
// https://site.com/testA.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question