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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:20:59+00:00 2026-05-28T05:20:59+00:00

Disclaimer : I realize asking Why doesn’t my regular expression work is pretty amateur.

  • 0

Disclaimer: I realize asking “Why doesn’t my regular expression work” is pretty amateur.

I have looked at the documentation, though I’m just plain struggling. I have a url (as a string) and what I want is to replace the placeholders (i.e. {objectID} and {queryTerm}

For a while now, I’ve been making attempts like this:

var _serviceURL = "http://my-server.com/rest-services/someObject/{objectID}/entries?term={queryTerm}";

var re1 = new RegExp("/{([A-Za-z])+}","gi");  
var re2 = new RegExp("/{([A-Za-z]+)}+","gi");  
var re3 = new RegExp("/{([A-Za-z])+}","gi");  
var re4 = new RegExp("/({[A-Za-z]+})+","gi");  
var re5 = new RegExp("({[A-Za-z]+})+","gi");  
var re6 = new RegExp("({[A-Za-z]}+)*","g");  
var re6a = new RegExp("({([a-z]+)})+","gi");  

var re7 = /{([^}]+)}/g;

var tokens =  re6A.exec(_serviceURL);
if (null != tokens.length ){
    for(i = 0; i < tokens.length; i++){
        var t = tokens[i];
        console.log("tokens[i]: " + t);
    }            
}
else {
    console.log("RegEx fail...")
}

re6a above produces an array like this upon execution:

tokens: Array[3]
    0: "{objectID}"
    1: "{objectID}"
    2: "objectID"

Related to the scenario above:

  1. Why is it I’m never getting the queryTerm ?
  2. Does the RegExp ‘i’ (ignore case) flag mean I can list a character class like [a-z] and also capture [A-Z] ?
  3. Which method of constructing a RegExp object is better? ...new RegExp(...); or var regExp = /{([^}]+)}/g; . In terms of “what’s better”, what I mean is cross-browser compatibility and as similar to other RegEx implementations (if I’m learning RegEx, I want to get the most value I can out of it).
  • 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-28T05:21:00+00:00Added an answer on May 28, 2026 at 5:21 am

    Does the RegExp i (ignore case) flag mean I can list a character class like [a-z] and also capture [A-Z]?

    Yes, it’ll capture them all.

    Which method of constructing a RegExp object is better? new RegExp(...) or var regExp = /{([^}]+)}/g;? In terms of “what’s better”, what I mean is cross-browser compatibility and as similar to other RegEx implementations (if I’m learning RegEx, I want to get the most value I can out of it).

    You should definitely use the literal notation.
    It gets compiled once at runtime, instead of every time you use it.
    They’re both equally cross browser compatible.


    All that said, I’d use this:

    _serviceURL.match(/[^{}]+(?=})/g);
    

    Here’s the fiddle: http://jsfiddle.net/CAugU/


    Here’s an explanation of the above regex:

    [    opens the character set
     ^    negates the set. Will only match whatever is NOT in these brackets
     {}   match anything that is NOT a curly brace
    ]    close the character set
    +    match that as many times as possible
    (?=  ascertain that it is possible to match the following here (won't be included in the match, this is called a lookahead)
     }    match a curly brace
    )    close the lookahead
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: I have little experience with linq. One of my tasks at my work
Disclaimer: I'm not a programmer, never was, never learned algorithms, CS, etc. Just have
Disclaimer: I realize I can generate this at runtime in Java, this was needed
Disclaimer Yes, I am fully aware that what I am asking about is totally
Disclaimer: I have no experience using YUI at all. I was wondering how the
Disclaimer: I've looked through all the questions I can find and none of them
Disclaimer: JS novice I have a JS widget that depends on JQuery. The widget's
Disclaimer: I'm working on Euler Problem 9. I'm adding up some pretty large numbers,
Disclaimer: I'm not actually trying to make one I'm just curious as to how
[Disclaimer: I am new to PHP, and I am just learning, so please no

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.