Search code examples
regexzapier

How to use lookahead and $ with Regex


I am trying to get the name of the resource, I will share with you the regexr url

My actual regular expression: ([^/]+)(?=\..*)

My example: https://res-3.cloudinary.com/ngxcoder/image/upload/f_auto,q_auto/v1/blog-images/5oonz9.jpg

I'm trying to get just 5oonz9

I tried to include $, but I don't know why it doesn't work

enter image description here


Solution

  • You can use:

    ^.+\/(.+)\..+$
    
    • ^.+ - From the start, match as many characters as possible
    • \/ - Match a literal /.
    • (.+) - Match one or more characters and capture them in a group
    • \. - Match a literal .
    • .+$ - Match one or more characters at the end of the string (the extension)

    Live demo here.