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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:08:34+00:00 2026-05-29T08:08:34+00:00

I have an large javascript array, 5000 or so entries. In order to run

  • 0

I have an large javascript array, 5000 or so entries. In order to run a RegExp match over all array items in a reasonably performant manner, I’d prefer not to loop exec and pull out groups. I’ve found the matching without grouping off exec to be much faster*.

  • http://jsperf.com/regexp-exec-vs-match-vs-test/4 (speed test)

Given javascript has no positive lookbehind operation, is it possible to take the following value and match only the numbers without hitting false positives using the standard regex toolkit?

    // the value to be matched
    var reference_field = ',1,3,8,123,';
    // a series of reference id to match
    var re = /(?:3|8)(?=,)/g;
    reference_field.match(re);
    // result, note that the second three was not intended --> ["3", "8", "3"]

If the array wasn’t so long, I’d just group the number, e.g.

    // the value to be matched
    var reference_field = ',1,3,8,123,';
    // a series of reference id to match
    var re = /,(3|8)(?=,)/g;
    var match;
    while(match = re.exec(reference_field)){
        if (match == null) {break;}
        // do something with match[1]
    }

… but as it stands, I’m sensitive to speed as mobile is a target platform. Am I missing a piece of regex trickery, or is it not possible without grouping. All the javascript positive lookbehind alternatives either don’t work (negative lookahead on the comma), or introduce additional processing overhead.

  • 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-29T08:08:35+00:00Added an answer on May 29, 2026 at 8:08 am

    The \b sequence could work for you — it matches a word boundary, both the beginning and end of words. If you know your strings are always these comma-separated number lists then this would find appropriate matches:

    /\b(?:3|8)\b/g
    

    You also wouldn’t need the extra commas at the start and end of reference_field.

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

Sidebar

Related Questions

if I have a large javascript string array that has over 10,000 elements, how
I have a very large txt file javascript array - too big for me
I have a very very large array of 44,000+ objects in a javascript file.
I have a large javascript which I didn't write but I need to use
I have a large, hi-def JavaScript-intensive image banner for a site I'm designing. What
I am creating a large table dynamically using Javascript. I have realised the time
We have a very large JavaScript application, where after many months of coding there
I have a javascript rich page that is passing a large JSON formatted to
I have read this question: Deleting array elements in JavaScript - delete vs splice
I have several large Javascript files that I need to document/digg into. Unfortunately I

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.