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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:39:34+00:00 2026-06-10T21:39:34+00:00

Do you know the purpose of (^|\s) in the following expression? /(^|\s)(apple|orange|lemon)(\s|$)/.test(foo);

  • 0

Do you know the purpose of (^|\s) in the following expression?

/(^|\s)(apple|orange|lemon)(\s|$)/.test(foo);
  • 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-10T21:39:35+00:00Added an answer on June 10, 2026 at 9:39 pm

    (^|\s) matches the start of the string or a whitespace character.

    So it will match if the string says “apple it is”, or if it says “I want an apple”.

    Do note that in the first case, it will match “apple “, and in the second case it matches ” apple”.

    Notice the extra space matched. If that behaviour is not desired, then a word boundary should be used instead (given by \b).

    Eg:

    /\b(apple|orange|lemon)\b/
    

    That would allow all apples matched to match “apple” exactly (instead of ” apple ” or other variants).

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

Sidebar

Related Questions

I run the following code on a Windows platform. The purpose is the know
I'm using the following regular expression ^[a-zA-Z0-9\',!;\?\$\^:\\\/`\|~&\" @#%\*\{}\(\)_\+\.\s=-]{1,1000}$ I know it's ugly, but so
I know what Cythons purpose is. It's to write compilable C extensions in a
I am a Zend developer. I just want to know the real purpose of
I have been curious to know what is the purpose of having a console
Does anyone know of a Twitter service proxy in particular, or a general-purpose REST
Ok, I know the difference in purpose. GET is to get some data. Make
I have the following code int m[4]={1,2,3,4}, *y; y=m; *y = f(y++); // Expression
What purpose does using serve when used the following way:- ONE EXAMPLE IS THIS,
With the following c++ example(indention was left out in purpose). if(condA) // if #1

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.