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 1049559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:38:07+00:00 2026-05-16T16:38:07+00:00

I’ve been at this for hours — I think I need sleep… but no

  • 0

I’ve been at this for hours — I think I need sleep… but no matter how I alter the expression javascript will only capture the 1st and 3rd elements:

var number = 09416;
var mat = "([0-9]+/[0-9]+/[0-9]+\\s+[0-9]+:[0-9]+)\\s+([A-Z]+)\\s+[0-9,]+\\s+(.*?"+number+".+)";
//          month / day / year      hour  :  min        AMPM      byte size    filename containing number in middle
var pattern = new RegExp(mat,"gi");
var arr = ['09/07/2010  07:08 PM                1,465,536 BOL09416 BOL31.exe',
           '09/06/2010  12:13 PM                  110,225 BOL09416_BOL030.exe',
           '09/08/2010  04:46 AM                   60,564 BOL09416_BOL32.exe',
           '09/08/2010  01:08 PM                   63,004 bol09416_bol33.exe']
for (var i=0;i<arr.length;i++){
     var match = pattern.exec(arr[i]);
     alert(match);
}

It is all spaces (no tabs), I’ve rewriten the regex to be as explainatory as possible… It correctly matches on arr[0] and arr[2], but nulls on the other two.
Tried looking for possible typo’s, trying different .+,.*,.+? etc. All online matchers show that it should be working: Example

Anybody have any ideas as to what I’m missing?

====================
Update:

Going through all the awesome suggestions I am stumped even further:

var match = arr[i].match(/([0-9]+\/[0-9]+\/[0-9]+\s+[0-9]+:[0-9]+)\s+([A-Z]+)\s+[0-9,]+\s+(.*?09416.+)/g);

gives match[0] = full string match[1] = undefined. Basically no captures.

where as:

var match = /([0-9]+\/[0-9]+\/[0-9]+\s+[0-9]+:[0-9]+)\s+([A-Z]+)\s+[0-9,]+\s+(.*?09416.+)/g.exec(arr[i]);

DOES return match[0] = full string, match[1] = date, and so on.

So I guess my real question is how to include dynamically made RegExpressions, and have multiple captures? As the only difference between:

var number = "09416";
var mat = "([0-9]+/[0-9]+/[0-9]+\\s+[0-9]+:[0-9]+)\\s+([A-Z]+)\\s+[0-9,]+\\s+(.*?09416.+)";
var pattern = new RegExp(mat,'g');

and

/([0-9]+\/[0-9]+\/[0-9]+\s+[0-9]+:[0-9]+)\s+([A-Z]+)\s+[0-9,]+\s+(.*?09416.+)/g.exec(arr[i]);

is that I hard-typed the number.

  • 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-05-16T16:38:08+00:00Added an answer on May 16, 2026 at 4:38 pm

    var number = 09416;
    // month / day / year hour : min AMPM byte size filename containing number in middle
    var mat = ‘^(\d{2}\/\d{2}\/\d{4})\s+(\d{2}:\d{2}\s*[AP]M)\s+((\d+[\d,]?))\s+(.‘ + number + ‘.*)$’;

    var pattern = new RegExp(mat);
    
    var arr = ['09/07/2010  07:08 PM                1,465,536 BOL09416 BOL31.exe',
               '09/06/2010  12:13 PM                  110,225 BOL09416_BOL030.exe',
               '09/08/2010  04:46 AM                   60,564 BOL09416_BOL32.exe',
               '09/08/2010  01:08 PM                   63,004 bol09416_bol33.exe']
    
    for (var i=0;i<arr.length;i++){
         var match = arr[i].match(pattern);
         console.log(match);
    }
    

    Use string.match instead of regex.exec.

    Edited
    I’ve removed the global and it worked like it should be. I’ve also rewritten the regex but it’s quite close to yours (not a big deal).

    Look at the output by firebug below:

    ["09/08/2010 04:46 AM ...,564 BOL09416_BOL32.exe", "09/08/2010", "04:46 AM", "60,564", "564", "BOL09416_BOL32.exe"]
    
    0 "09/08/2010 04:46 AM ...,564 BOL09416_BOL32.exe" //whole match
    1 "09/08/2010" //date
    2 "04:46 AM" //time
    3 "60,564" //bytes
    4 "564" // last digit of bytes (i can't take this off. but it's harmless)
    5 "BOL09416_BOL32.exe" //name of file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.