S
S
serezhaseo2021-07-02 15:39:29
JavaScript
serezhaseo, 2021-07-02 15:39:29

How to set an exception in regular expressions? From .jpg to the first "/" from the end?

Purpose: to rename the path to the picture.

I make regular expressions through https://regex101.com/ in the standard form, then I use them, I'm not a programmer.
Faced such a problem: images on the source site are stored in different folders and at different nesting levels, for example:

src="/sites/default/files/resize/m14/4m213/3567705_images_12175409452-.jpg
src="/sites/default/files /resize/afaf/5814f65f91ef731c793433fe5096e892-.jpg
src="/sites/default/files/resize/test/640m-.jpg
src="/sites/default/files/resize/5173.970-.jpg
src="/sites/default /files/resize/a/b/3/5main_br_xl-.jpg
src="/sites/default/files/resize/images/m8/image8-.jpg

I need to leave only its name from each of these images,
3567705_images_12175409452-.jpg
5814f65f91ef731c793433fe5096e892-.jpg

etc.

Previously, the path was standard and I simply replaced it with my own. Tell me how to make a regular expression to exclude everything from .jpg to the first slash from the end (or your own logic)

that's what I tried but it doesn't work out exclude the name itself from .jpg

https://regex101.com/r/3WISBV/1

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
N, 2021-07-02
@serezhaseo

https://regex101.com/r/IgRWLx/1

S
SOTVM, 2021-07-02
@sotvm

regex is not needed for this,
find ./ -name *.jpg
but then pass the output of find to any command

V
v3shin, 2021-07-02
@v3shin

/src="(.*?\\/)([^\/"]+)"/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question