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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:39:13+00:00 2026-06-14T18:39:13+00:00

Does any body know what the algorithm used for the search() function in javascript

  • 0

Does any body know what the algorithm used for the search() function in javascript is?

var myRegExp = /Alex/;
var string1 = "Today John went to the store and talked with Alex.";
var matchPos1 = string1.search(myRegExp);

if(matchPos1 != -1)
    document.write("There was a match at position " + matchPos1); 
else
    document.write("There was no match in the first string");

Example copied tizaq.com

I need to use this function to search a text document for different string values. But I need to document what the algorithm behind this method is, and what the complexity is. Otherwise I have to write my own method that searches the text file that I have.

  • 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-14T18:39:14+00:00Added an answer on June 14, 2026 at 6:39 pm

    The specification says it’s implemented as a regular expression match:

    3) If Type(regexp) is Object and the value of the [[Class]] internal
    property of regexp is “RegExp”, then let rx be regexp;

    4) Else, let rx be a new RegExp object created as if by the
    expression new RegExp( regexp) where RegExp is the standard built-in
    constructor with that name.

    5) Search the value string from its beginning for an occurrence of
    the regular expression pattern rx. Let result be a Number indicating
    the offset within string where the pattern matched, or –1 if there was
    no match. (…)

    (Section 15.5.4.12 String.prototype.search (regexp)).

    This means your question boils down to the regex matching algorithm. But that is not in the specification either, it depends on the implementation:

    The value of the [[Match]] internal property is an implementation dependent representation of the Pattern of the RegExp object.

    (Section 15.10.7 Properties of RegExp Instances).

    So, if documenting the complexity of that algorithm is really a requirement, I guess you’ll have to write your own method. But keep in mind that, by doing that, you’ll probably come up with something less efficient, and probably dependent on other built-in methods whose complexity is unknown (maybe even RegExp itself). So, can’t you convince the powers that be that documenting the complexity of a built-in, implementation-dependent js method is not your job?

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

Sidebar

Related Questions

Does any body know how to set different select statement for the same cursor?
Does any body know how can I use MS_MPI in my VC++ MFC project?
does any body know how to show the horizontal scroller on tree panel... since
Does any body know why some columns in postgres is shown as double quotes
Does anybody know any algorithm which generates unique 8 or 9 digits number for
Does any body know if Telerik has any control that supports drawing of Organization
Does any body know how browser(IE, Firefox, Chrome) load web page? I think they
Does any body know how to write an XML from a Dataset that has
Does anybody know of a working code example of the sum-product algorithm for (loopy)
Does anybody know why this function, when passed an invalid date (e.g. timestamp) to

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.