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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:01:46+00:00 2026-06-15T07:01:46+00:00

I am trying to match all words with single or multiple spaces. my expression

  • 0

I am trying to match all words with single or multiple spaces. my expression

(\w+\s*)* is not working

edit 1:
Let say i have a sentence in this form

[[do "hi i am bob"]]
[[do "hi   i am Bob"]]

now I have to replace this with 
cool("hi i am bob") or 
cool("hi    i am Bob")

I do not care about replacing multiple spaces with single .

I can achieve this for a single word like

\[\[do\"(\w+)\"\]\] and replacing regex cool\(\"$1\") but this does not look like an effective solution and does not match multiple words ….
I apologies for incomplete question

any help will be aprecciated

  • 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-15T07:01:48+00:00Added an answer on June 15, 2026 at 7:01 am

    Find this Regular Expression:

    /\[\[do\s+("[\w\s]+")\s*\]\]/
    

    And do the following replacement:

    'cool($1)'
    

    The only special thing that’s being done here is using character classes to our advantage with

    [\w\s]+
    

    Matches one or more word or space characters (a-z, A-Z, 0-9, _, and whitespace). That’;; eat up your internal stuff no problem.

    '[[do "hi   i am Bob"]]'.replace(/\[\[do\s+("[\w\s]+")\s*\]\]/, 'cool($1)')
    

    Spits out

    cool("hi   i am Bob")
    

    Though – if you want to add punctuation (which you probably will), you should do it like this:

    /\[\[do\s+("[^"]+")\s*\]\]/
    

    Which will match any character that’s not a double quote, preserving your substring. There are more complicated ones to allow you to deal with escaped quotation marks, but I think that’s outside the scope of this question.

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

Sidebar

Related Questions

I am trying to write a replacement regular expression to surround all words in
I'm trying to match only when all space-separated words are longer than 3 word
I am trying to write a script that will match all words in a
I'm trying to return a count of all words NOT between square brackets. So
I'm trying to do a preg match all on the response below to get
Given the HTML below, I am trying to use jQuery to match all the
I am trying to match on a string that begins with ./media I have
I am trying to match words driven from a database in a string input
Hello All , I am trying to use preg_match to identify if a single
So I'm trying to fetch objects from core data. I have list of say

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.