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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:44:45+00:00 2026-05-12T10:44:45+00:00

Can you guys help me figure this out? I have the following JavaScript snippet:

  • 0

Can you guys help me figure this out? I have the following JavaScript snippet:

pattern = new RegExp('^bla*a', 'i');
console.debug(pattern.exec('blatr'));

After I run this, the output is [“bla”].
The way I interpret this regular expression is this: find me a string that starts with ‘bla’ and ends with ‘a’, with as many characters in between. In this case, ‘blatr’ shouldn’t match the regular expression but it does.
What am I doing wrong?

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-05-12T10:44:45+00:00Added an answer on May 12, 2026 at 10:44 am

    The a* in your expression is matching the preceding character a zero or more times, not the string bla. You’ll need to use parentheses. Try this:

    new RegExp('(^bla){1}.+a$', 'i');
    

    EDIT: No point in using + in an expression that matches the beginning of a string. Also, since you say you want to match any characters in between bla and a you’ll need to use a + after the .

    EDIT: Ahem, seems one doesn’t need parentheses either as the other answers show. Note to self: Stop over-engineering your RegEx’s and test your answers before you post them. 😛 This is fine:

    new RegExp('^bla.+a$', 'i');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have this quick bit of code that I can't figure out
I hope some of you guys can help me with this problem.... I have
Hi Guys can you please help me with this error? What is it? Server
I have another error, unexpected type required:variable found:value and I can't figure out why.
I wonder if you can help me with this one. I have looked on
Hello StackOverflow Community, I hope you guys can help me with this here: On
Alright I have been trying to figure this out and I read the MSDN
Hi guys i've been trying to figure out this problem for an hour or
I'm learning Ruby right now and I got stuck, maybe you guys can help
Intro I work in a facility where we have microscopes. These guys can be

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.