Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:17:42+00:00 2026-06-12T00:17:42+00:00

Am I putting regex the correct way here to filter out image filename and

  • 0

Am I putting regex the correct way here to filter out image filename and filetype?

^(\w)+\.(jpg|png|gif)$

the link to the exercise is here:
http://regexone.com/example/4?

The exercise is To capture the name and the extension from a list of files:

task           text                  capture
skip text      .bash_profile        
skip text      workspace.doc        
capture text   img0912.jpg          img0912, jpg    
capture text   updated_img0912.png  updated_img0912, png    
skip text      documentation.html       
capture text   favicon.gif          favicon, gif    
skip text      img0912.jpg.tmp      
skip text      access.lock
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:17:43+00:00Added an answer on June 12, 2026 at 12:17 am

    You have only one mistake:

    You capture only the last character of the filename with (\w)+. This is called “repeat a capturing group“, that is not what you want here. Put the quantifier inside the group to capture the complete name.

        (\w+)
    

    Some notes

    1. The starting anchor “^” is not necessarily needed, depends on what you are looking for. For that example it would make no difference.

    2. \w works for your example, but will not capture all valid filenames, because it contains only Letters, Digits and the Underscore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a hard time figuring out this XSD Regex match. Here is
When putting a favicon on your site, you can apparently use an animated gif,
Just putting part of some code here where I am writing two values to
Putting a precompiled regex inside two different hashes referenced in a list: my @list
i need help with creating a regex for putting all values into an array!
Here is an example backup file I will be putting in preg_match to find.
New to regex and I'm having difficulty putting together a regex argument for this
Regex parsing problem, I am putting together an embed video provider module for Drupal.
I am having a little problem with putting a regex inside a sed command,
I kind of know how preg_replace works but I am horrible with regex. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.