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

  • Home
  • SEARCH
  • 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 8539223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:18:47+00:00 2026-06-11T11:18:47+00:00

I suck at regex. I have a php function that will read through a

  • 0

I suck at regex. I have a php function that will read through a directory of filenames on my server, and I am trying to pull out filename data from one specific filename, but am failing miserably. Here is what I have thus far:

$file = 'VERSION_3.7.1b.txt';
$VersionNumber = preg_match('#^(VERSION_)[^\s]*\.\.[^\s]+(\.(txt))#', $file);

I am trying to have the preg_match only return true for files that begin with ‘VERSION_’ and end with ‘.txt. The stuff in the middle may be any variety of numbers, letters, periods…and that is the part I want to return. So in this case, I want $VersionNumber to end up set as ‘3.7.1b’

Other filenames that would return something are like these:

VERSION_3.txt  ->  3
VERSION_3.7.txt  ->  3.7
VERSION_3.7e.1.txt  ->  3.7e.1
VERSION_2012.09.13.3.7.1b.txt  ->  2012.09.13.3.7.1b
VERSION_3.7.20120913.txt  ->  3.7.20120913

Any regex masters out there that can explain to me if I am even close? Thanks!

  • 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-11T11:18:49+00:00Added an answer on June 11, 2026 at 11:18 am

    You’ll want to pass a variable for $matches as well.

    I simplified your RegExp. Try this:

    $file = 'VERSION_3.7.1b.txt';
    preg_match('/^VERSION_(.*?)\.txt/', $file, $matches);
    echo $matches[1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple php function that will strip everything between two
Guys I hate Regex and I suck at writing. I have a string that
As an exercise, I'm trying to create a input stream manipulator that will suck
I have this regex in PHP: $regex = '/<img[^>]*'.'src=[\|\'](.*)[\|\']/Ui'; It captures all image tag
I have a snippet of code im trying to parse with nokogiri that looks
I have a system that needs to suck up an entire MS SQL database.
First, let me say this: I suck at regex and htaccess. I'm trying to
So out of all of my php skills, I just suck at regular expressions.
I suck at php, and cant find the error here. The script gets 2
My current solution will suck sometimes EDIT For those who don't understand,see this example:

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.