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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:02:32+00:00 2026-06-07T12:02:32+00:00

I have a script that searches through urls and looks for a certain domain

  • 0

I have a script that searches through urls and looks for a certain domain name, then appends some parameters to the end of the url. However, if run more than once, it will add duplicate parameters to the same url. Is it possible check if the url already has parameters on it?

JSFiddle

original stackoverflow post

code being modified

<div id="wp-content-editor-container" class="wp-editor-container"><textarea class="wp-editor-area" rows="10" tabindex="1" cols="40" name="content" id="content">&lt;a title="Link to test domain" href="http://www.domain.com"&gt;Link to google&lt;/a&gt;
&lt;a href="http://google.com/directory/subdirectory/index.html"&gt;This is another link&lt;/a&gt;
&lt;a href="http://domain.com/directory/index.html"&gt;This is a 3rd link&lt;/a&gt;

&lt;a href="http://www.domain.com/subdir?parameter"&gt;this url already has parameters&lt;/a&gt;</textarea></div>

jquery script

var url = 'www.domain.com';
var append = '?parameter';

$(".wp-editor-area").each(function() {
    $(this).text(urlify($(this).text()));
});

function urlify(text) {
    var urlRegex = /(\b(https?|ftp|file):\/\/[www.domain.com][-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(urlRegex, function(url) {
        return url + append;
    })
}

current output

<a title="Link to test domain" href="http://www.domain.com?parameter">Link to google</a>
<a href="http://google.com/directory/subdirectory/index.html">This is another link</a>
<a href="http://domain.com/directory/index.html?parameter">This is a 3rd link</a>

<a href="http://www.domain.com/subdir?parameter?parameter">this url already has parameters</a>

The ideal output would not add a second “?parameter” at the end of the url ^

Thanks!

  • 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-07T12:02:35+00:00Added an answer on June 7, 2026 at 12:02 pm

    I think you can use indexOf to check if the URL already contains what you are trying to append.

      function urlify(text) {
                    var urlRegex = '/(\b(https?|ftp|file):\/\/[www.domain.com][-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig';
                    return text.replace(urlRegex, function (url) {
                        // if the url does not contain append, concat append to the URL
                        if (url.indexOf(append) == -1) {
                            return url + append;
                        }
                        return url;
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently im faced with the following problem: I have a script that searches through
I have a script that searches for a directory containing a specific file, starting
I have a line in a bash script that searches for a folder using
At the minute I have a page with an AJAX script that searches a
I have a script that recursively loops through all the sub directories and compresses
If I have a script that writes 1000 lines to file and then continues
So I have a script that grabs a <tr> and iterates through it to
I have a simple search script that takes user input and searches across directories
I have a jquery script that searches a php file that produces an XML
I have a webpage that looks like: <html> <head> <title>Hi</title> </head> <body> <form name=mainForm

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.