I'm trying to match such that all the characters after the last /
and before .
gets matched. My current challenge is that .
is only sometimes present.
I have an example here: https://regex101.com/r/ThWZwX/3
Where I'm hoping to match the 'match' text in both scenarios.
Thanks,
You can use negated character class in a capture group without any need of a lookahead:
.*\/([^.]*)
We use .*\\/
to match last /
by using a greedy match of .*
and then we use negated character class [^.]*
to match until we get a dot or everything if dot is not found.
Also note that we use ([^.]*)
to capture this match.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.