How does regular match Theme/home/images/logo.jpg's logo.jpg?

Source: Internet
Author: User
Title
The file name in front of the. jpg may be underlined by a numeric letter
A friend answered with \w+\.jpg, the effect can be achieved. Another way of thinking, to match the value behind a slash? How do you write regular expressions?

Reply content:

Title
The file name in front of the. jpg may be underlined by a numeric letter
Have a friend to answer with \w+\.jpg , can achieve effect. Another way of thinking, to match the value behind a slash? How do you write regular expressions?

Regular:\w+\.jpg$
String functions:strrchr($str, '/')

If not, you can use BaseName ()

Is this hard? Why is it all so complicated?

var reg = /[^/]*$/

I think too much, let's not talk to me.

I think it's possible.

var regex = /(?:[^\/]*\/)(\w+\.jpg)/;var str = "Theme/Home/images/logo.jpg";regex.exec(str)//["images/logo.jpg", "logo.jpg"]

/(?:[^\/]*\/)(\w+\.jpg)/, where the (?:) grouping is not captured and (\w+\.jpg) is a capturing group.
regex.exec(str), the first array element is the string that matches the whole, and the second element is the content that the first capturing group matches to.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.