There's an address like 'media/dir1/dir2/file.png', except for the file name I want to extract only this part of media/dir1/dir2/
'.+(?<=/)' This regular expression succeeded.
But I don't know exactly why I succeeded.
In particular, if '(?<=/)' rear search was successful in the rear search, why only the rear search disappeared? I wonder if the front part including / comes out as a result.
regex
in front of the parentheses subexpression (
, (...)
)?If =?!
, ?<=
or ?<!
appears, lookaround is applied. At this point, the matched area in subexpression will leave as an empty character.
Therefore, .+(?<=/)
treats the last matching /
as an empty character and outputs all characters before that.
In addition, forward searching seems to be more appropriate in meaning than backward searching here.
.+(?=/)
The meaning of the forward search expression above means that all characters must be printed before the last /
character is found.
© 2024 OneMinuteCode. All rights reserved.