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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:30:26+00:00 2026-06-14T09:30:26+00:00

I have the following javascript string /Library/Application%20Support/Adobe/Fireworks%20CS6/Commands The numeral in the CS# section may

  • 0

I have the following javascript string

/Library/Application%20Support/Adobe/Fireworks%20CS6/Commands

The numeral in the “CS#” section may change, but I would like to convert the string to the following format keeping in mind that the numeral may change.

/Library/Caches/Adobe/TypeSupport/CS6

I know I can do this in several ways, but for the purpose of education I am looking for the best method.

I can search with a regular expression using the replace method, but is it possible to use matches in the replacement?

Thanks for any help

  • 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-14T09:30:27+00:00Added an answer on June 14, 2026 at 9:30 am

    The simplest solution is to use parentheses in the regular expression to capture the part of the original string you wish to use in the replacement, and then include that in the replacement string via the special sequence $1. For your example:

    '/Library/Application%20Support/Adobe/Fireworks%20CS6/Commands'.replace(
        /^.*\/(CS[0-9]+).*$/, 
        '/Library/Caches/Adobe/TypeSupport/$1'); 
    // => /Library/Caches/Adobe/TypeSupport/CS6
    

    (You can have more than one set of parentheses, in which case subsequent groups are $2, $3, etc. Sometimes the string you care about happens to be exactly what matches the entire regular expression, in which case you can just use $& in the replacement string , and don’t need any parentheses.)

    This is great for simply including literal text from the source string, as you’re doing.

    If you’re doing anything a bit fancier, however – such as trying to change the case of the matched text – it won’t work. ('$1'.toLowerCase() will simply convert the literal string ‘$1’ to lowercase before passing it to replace; not helpful.) For those situations, you can use a function instead of a string as the replacement. It will be called once per match, and passed the part of the string that matched (equivalent to $& in the string version); if there are parentheses in the regex, it will be passed an additional parameter containing the match for each group, in order. So you could convert your example to lowercase like this:

    '/Library/Application%20Support/Adobe/Fireworks%20CS6/Commands'.replace(
            /^.*\/(CS[0-9]+).*$/, 
            function(whole_match, cs_number) { 
              return "/Library/Caches/Adobe/type_support/" + cs_number.toLowerCase()
            });  
    // => /Library/Caches/Adobe/type_support/cs6
    

    You can read the Mozilla spec/documentation here.

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

Sidebar

Related Questions

I'm a bit rusty on my regexp and Javascript. I have the following string
I have the following HTML code stored in a javascript string: and I am
I have the following text inside a javascript string variable: here is some text
Imagine I have the following multi-line Javascript string: school apple ~carrot dog I want
I have the following text as a JavaScript string .mybox { display: block; width:
I have following string in javascript. str = '<a href=/display/1>This is link</a>'; I want
Here's a string that I may have: (MyStringIsOneWholeWord *) I have used the following
I have the following JavaScript data structure. a[] is an array with text strings
I have the following JavaScript/jQuery code that starts the listener that highlights the DOM
I have the following Javascript code that works perfectly: $(document).ready(function() { $(#Select1).setDefault(); $(#Select2).setDefault(); $(#Select3).setDefault();

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.