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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:12:15+00:00 2026-06-12T07:12:15+00:00

The regular expression I am using is returning too much text. The expression is

  • 0

The regular expression I am using is returning too much text. The expression is supposed to strip out a name and date from the text.

var sCurrentText = "(26 JAN 2011) - ILewis Provided excellent translation.";
var sRegxDate    = "\([0-9]{2}[\\\.\/\-, ](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[\\\.\/\-, ][0-9]{4}\)[, \-]{0,3}[A-z]+ ?\-?\:? ?";
var DatePattern  = new RegExp(sRegxDate, "i");
var sDate        = DatePattern.exec(sCurrentText);
alert(sDate);

I expect:

(26 JAN 2011) - ILewis

But the popup says:

(26 JAN 2011) - ILewis,JAN

Other annoying issues:

  1. I am not able to emulate this issue in regexpal. http://regexpal.com/

2.

alert(sDate[0]); 

returns:

(26 JAN 2011) - ILewis

but

oTextbox.value = sDate[0];

results in an empty textbox. Frustrating.

What am I doing wrong?

  • 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-12T07:12:16+00:00Added an answer on June 12, 2026 at 7:12 am

    You are alerting sDate thinking that it is a string, when in fact it is an array. The comma isn’t in the match, it is a separater.

    The first element is:

    (26 JAN 2011) - ILewis
    

    The second is:

    JAN
    

    This is because you have the month bit wrapped in parentheses. It is a capturing group and exec returns capturing groups as part of the result.

    You want

    sDate[0]
    

    If you are getting an empty textbox from this, there is some other issue here outside of the regex.

    You also have some improperly escaped \ in your regex. As it is there, it does not work at all in IE. You need \\ wherever you have a \

    EDIT: This fiddle shows the code in action. It works.

    http://jsfiddle.net/5azr9/

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

Sidebar

Related Questions

From the list of text junk I'm using regular expression. The following will do
I'm having some trouble using regular expression to get date in a string. Example
'123xswer' How to retrieve 123 from the string above without using regular expression?
I'm using RUBY 's regular expression to deal with text such as ${1:aaa|bbbb} ${233:aaa
What regular expression using java could be used to filter out dashes '-' and
I'm having problems using substr() with matches coming from a regular expression (using preg_match()
how to shift the top element from array based on a regular expression using
I am using regular expression to filter the invalid input entered by the end
I want to validate mathematical expressions using regular expression. The mathematical expression can be
I need to improve on a regular expression I'm using. Currently, here it is:

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.