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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:31:51+00:00 2026-06-10T01:31:51+00:00

I have a problem to do a replace in javascript with regex this is

  • 0

I have a problem to do a replace in javascript with regex

this is the code

var link = document.getElementsByTagName('a');
var i = link.length;
   while(i--){
      var lnk = link[i].href;
       lnk.replace('/^http\:\/\/www\.ringtonematcher\.com\/go\/\?sid\=([\w]+)\&/g', 'test');
    }

sid=replace& = sid=test&

  • 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-10T01:31:54+00:00Added an answer on June 10, 2026 at 1:31 am

    I guess your problem is that you don’t do anything with the result of the replace method. It does not alter anything, but returns a new string. If you’d want to change the href attributes, you will need to reassign it:

    var links = document.getElementsByTagName('a');
    for (var i=0; i<links.length; i++) {
        var lnk = link[i].href;
        var newlnk = lnk.replace(/^http:\/\/www\.ringtonematcher\.com\/go\/\?sid=(\w+)&/g, 'test$1');
        link[i].href = newlnk;
    }
    

    I also fixed some flaws in your regex:

    • It needs to be a regex literal, not a string (remove the apostrophes)
    • You don’t need to escape the :, = or & characters
    • You don’t need to wrap the character class shortcut \w in a character class
    • You don’t want the \w+ to be greedy
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this regex/javascript code: toReturn = toReturn.replace(/(\[url=)(.+)(\])(.+)(\[\/url\])/g, '<a target=\_blank\ href=\$2>\$4</a>'); But the problem
I have this function for my sql javascript PATH=http://localhost/dhodia/; try{ var tags=url.replace(PATH,); var spl=tags.split(/);
I have a problem with the replace method of javascript. I have a string
I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
I'm have a problem with this code not working when it probably should be:
I have a problem with JavaScript code, it works in IE7/8, but doesn't work
I have another Javascript regex conundrum... (apologies if this is a bit long-winded -
I have a problem with one JSF page. This is the source code: <!DOCTYPE
I have a problem how do i replace a single dash(-) with a single
I have a huge problem with the REPLACE SQL function in Microsoft SQL Server

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.