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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:43:34+00:00 2026-06-06T13:43:34+00:00

I have a string with one or more placeholders in the following format: $(

  • 0

I have a string with one or more placeholders in the following format: $([name])

The [name] can be any word (containing alfanumeric chars) and is case sensitive.

 Example1: 'The $(Quick) Brown fox jumps over the lazy dog'
 Example2: '$(the) $(Quick) Brown fox jumps over $(the) lazy dog'
 Example3: '$(the) $(Quick) Brown $(fox) jumps over $(the) lazy $(dog)'

What is the best way in javascript to retrieve all place holders so that we have following result:

 Example1: ['Quick']
 Example2: ['the', 'Quick', 'the']
 Example3: ['the', 'Quick', 'fox', 'the', 'dog']

I also need to retrieve a unique list of placeholders, thus:

 Example1: ['Quick']
 Example2: ['the', 'Quick']
 Example3: ['the', 'Quick', 'fox', 'dog']

Thank you.

  • 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-06T13:43:36+00:00Added an answer on June 6, 2026 at 1:43 pm

    As other answers have mentioned, your best approach is to use regular expression with the JavaScript string.match() function. My regular expression isn’t the best it could be [whose is], but this should do the trick:

    jsFiddle Demo

    function getPlaceholders(str)
    {
        var regex = /\$\((\w+)\)/g;
        var result = [];
    
        while (match = regex.exec(str))
        {
            result.push(match[1]);    
        }
    
        return result;
    }
    

    Thanks freakish
    ​

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

Sidebar

Related Questions

I have a string (coming from ASP.NET) which contains one or more placeholders. In
I have one string name as id in my .aspx.cs page and one JavaScript
I have 1 string contaning html and one string contaning css is there any
I have a string like this one text more text empty space . How
I have a string array like this. string[] queries with data more than one
I have a string that is defined as one or more dot-separated integers like
I have following string task BLABLA@{taskId} @{BLABLA.title} and want to extract all placeholders from
I want to check if my string contain one or more asterisk. I have
If I have a function which accepts more than one string parameter, the first
I have a gridview which can be filtered from one or more values in

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.