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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:19:44+00:00 2026-06-01T16:19:44+00:00

I want to replace the src attribute for all images matching a regex using

  • 0

I want to replace the src attribute for all images matching a regex using Greasemonkey scripting.
Example:

Replace http://aff.kooora.com/i/z3.gif

With http://example.com/aff.kooora.com/i/z3.gif

I have no experience in scripting but this is what I came up with:

var allImg=document.getElementsByTagName("img"), i=0, img;
var pattern = aff\.kooora\.com/([A-Za-z0-9/._]*);
while(img=allImg[i++])
{
    result = pattern.exec(img);
    if (result!=null) 
        img.src=img.src.replace(result, 'http://example.com/' + result);
}

It doesn’t work.

  • 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-01T16:19:46+00:00Added an answer on June 1, 2026 at 4:19 pm

    Your regular expression is the problem, you need to wrap it in slashes (otherwise the interpreter has no clue that it should treat that as a regexp):

    var allImg=document.getElementsByTagName("img"), i=0, img;
    
    var pattern = /^http\:\/\/aff\.kooora\.com\/(.*)$/;
    
    while (img = allImg[i++])
    {
        if (img.src.match(pattern)) {
            img.src = img.src.replace(pattern, 'http://example.com/aff.kooora.com/$1');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use regex to replace src html attributes. The HTML is not
Possible Duplicate: Regex to change format of all img src attributes Hi, I want
I have some HTML and want to replace the src attributes of all the
I want to replace i# (look that the example inputs/outputs) with the value of
I want to replace all the occurrences of a dot( . ) in a
I want to locate all image tags in my html with src not containing
I would like to change the src attribute of an image on click using
I am currently using the code below to load images but I want to
Yes, I want to search and replace all the occurrences of the pattern and
I have a template where I want to replace certain regions. In my example

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.