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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:10:55+00:00 2026-06-05T07:10:55+00:00

Many times I’m using the string match function to know if a string matches

  • 0

Many times I’m using the string match function to know if a string matches a regular expression.

if(str.match(/{regex}/))

Is there any difference between this:

if (/{regex}/.test(str))

They seem to give the same result?

  • 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-05T07:10:58+00:00Added an answer on June 5, 2026 at 7:10 am

    Basic Usage

    First, let’s see what each function does:

    regexObject.test( String )

    Executes the search for a match between a regular expression and a specified string. Returns true or false.

    string.match( RegExp )

    Used to retrieve the matches when matching a string against a regular expression. Returns an array with the matches or null if there are none.

    Since null evaluates to false,

    if ( string.match(regex) ) {
      // There was a match.
    } else {
      // No match.
    } 
    

    Performance

    Is there any difference regarding performance?

    Yes. I found this short note in the MDN site:

    If you need to know if a string matches a regular expression regexp, use regexp.test(string).

    Is the difference significant?

    The answer once more is YES! This jsPerf I put together shows the difference is ~30% – ~60% depending on the browser:

    test vs match | Performance Test

    Conclusion

    Use .test if you want a faster boolean check. Use .match to retrieve all matches when using the g global flag.

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

Sidebar

Related Questions

Many times i am using code like this: public static void ExecuteMethod1InThread(string msg) {
Many times I see statements like following Y.CustomApp.superclass.render.apply(this, arguments); I know how apply works.
Many times I've seen a semicolon used after a function declaration, or after the
There are many times when I need to test a little snippet of .NET
Many times there is a clear method, that removes all the items from the
Many times when I run android application using Eclipse. Eclipse stuck on building the
Many times, I'm writing a function which will return true on success and false
Many times i have come accross a situation where there is a loop and
How many times is it permitted to have the jQuery document ready function declared
Many times I encounter a site, and would like to know - how did

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.