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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:09:41+00:00 2026-06-15T20:09:41+00:00

My pattern stops after the first match and it has the global match in

  • 0

My pattern stops after the first match and it has the global match in there.

//When I add [*]* like var pattern=/([^A-z0-9]|^|[*]*)_(\S.*?)_((?!\S)|\W)/g;
//  it works, but when I try to match "1_test1_" and "a_test1_" it matches "_test1_"
//  which I don't want. I know [*]* will match 0 or more instances of literal *
//  but [*]+ won't work due to the first match being "_test1_*"

var pattern=/([^A-z0-9]|^)_(\S.*?)_((?!\S)|\W)/g;

alert("_test1_*_test2_".match(pattern)); //=> _test1_*
    //This should match "_test1_*" first then it should also add to the array with "_test2_"

QUESTION START

I want the above (first code block) to alert “_test1_*,_test2_”
and I want the below (second code block) to remain the same (as shown by the commentend section).

I don’t know why _test2_ does not match because it matches perfectly with the tests shown below.

QUESTION FINISH

The following are tests and work as they should.

alert("_test1_ _test2_".match(pattern)); //=> _test1_, _test2_
alert("_test1_*".match(pattern)); //=> _test1_*
alert("_test2_".match(pattern)); //=> _test2_
alert("*_test2_".match(pattern)); //=> *_test2_
alert("1_test1_".match(pattern)); //=> null
alert("a_test1_".match(pattern)); //=> null
alert("_test1_1".match(pattern)); //=> null
alert("_test1_a".match(pattern)); //=> null
  • 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-15T20:09:42+00:00Added an answer on June 15, 2026 at 8:09 pm

    After numerous trial and error attempts I have finally found my answer by adding |\b. Thank you @Alih Nehpets for your attempts at answering my question.

    ([^A-z0-9]|^|\b)_(\S.*?)_((?!\S)|\W)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever glob pattern match fails, it stops the whole job. For instance, $ mv
how do i return after the first match of regular expression? (does the Matcher.find()
Is there anyway to get a regex pattern to automatically stop searching after one
The pattern i am trying to match is some characters(letters+digits+hyphens (-) ) then 5
This pattern pops up a lot. It looks like a very verbose way to
Observer pattern: There are 2 variants of it. Where Subjects informs all the observers
I know that there are many similar questions, but I don't understand most of
I have the following design pattern: var myObjectWithEvents = new ObjectWithEvents(); using (var mre
First I'd like to head off the wait a minute questions. Yes, I've read
I'm not a regex expert, but after a couple hours I've built this regex:

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.