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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:50:02+00:00 2026-05-15T14:50:02+00:00

I looked at several examples on how to use regex in JS but I

  • 0

I looked at several examples on how to use regex in JS but I can not seem to find the right syntax for what I need. Basically I have an array of words:

commonWords=["she", "he", "him", "liked", "i", "a", "an", "are"]

and a string:

'She met him where he liked to eat "the best" cheese pizza.'

Basically I want to use non-alphas and my array of commonWords as delimiters for extracting phrases. The above would yield somthing like this:

'met, where, to eat, the best, cheese pizza'
  • 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-15T14:50:02+00:00Added an answer on May 15, 2026 at 2:50 pm

    From the OP:

    “Basically I want to use non-alphas and my array of commonWords as delimiters for extracting phrases.”

    This does both (unlike some other answers 😉 ). It returns either a string or an array.

    var commonWords = ["she", "he", "him", "liked", "i", "a", "an", "are"];
    var SourceStr   = 'She met him where he liked to eat "the best" cheese pizza, didn\'t she, $%&#! Mr. O\'Leary?';
    
    //--- Kill (most) non-alphas, and the keywords replace with tab.
    var zRegEx      = eval ('/([^0-9a-z\' ]+)|\\s*\\b(' + commonWords.join ("|") + ')\\b\\s*/ig');
    var sPhraseList = SourceStr.replace (zRegEx, '\t');
    
    //-- Trim empty results and leading and trailing delimiters.
    sPhraseList     = sPhraseList.replace (/ *\t+ */g, ', '). replace (/, ?, ?/g, ', ');
    sPhraseList     = sPhraseList.replace (/(^[, ]+)|([, ]+$)/g, '');
    
    //-- Make optional array:
    aPhraseList     = sPhraseList.split (/, */g);
    
    //-- Replace "console.log" with "alert" if you're not using Firebug.
    console.log (SourceStr);
    console.log (sPhraseList);
    console.log (aPhraseList);
    

    .
    This returns:

    "met, where, to eat, the best, cheese pizza, didn't, Mr, O'Leary"
    
    and
    
    ["met", "where", "to eat", "the best", "cheese pizza", "didn't", "Mr", "O'Leary"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked through several posts but I haven't quite found any answers that have
I have looked at several options like: * http://blog.waynehartman.com/archive/2012/01/07/uistoryboard-on-ios-5-the-good-the-bad-and-the.aspx * UIPopoverController Anchor Position *
I've looked at several other suggestions on this issue but for some reason my
I've looked at several questions here that looked similar, but none of them discussed
I have looked through several sites for any useful documentation and have come up
Ok so I have looked up several ways of getting this done, and none
In Perl, how can I use one regex grouping to capture more than one
When using ColdFusion ORM where you have several tables with relationships can I bind
My Research: Okay, I have looked at dozens upon dozens of examples for Write-Progress
We have several ASP.NET applications that use a sitemap which is populated via a

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.