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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:04:04+00:00 2026-06-09T23:04:04+00:00

I’m using an application to search this website that I don’t have control of

  • 0

I’m using an application to search this website that I don’t have control of right this moment and was wondering if there is a way to ignore duplicate matches using only regex.

Right now I wrote this to get matches for the image source in the pages source code

uses this to retrieve srcs

<span> <img id="imgProduct.*? src="/(.*?)" alt="

from this

<span> <img id="imgProduct_1" class="SmPrdImg selected"     
onclick="(some javascript);" src="the_src_I_want1.jpg" alt="woohee"> </span>
<span> <img id="imgProduct_2" class="SmPrdImg selected"     
onclick="(some javascript);" src="the_src_I_want2.jpg" alt="woohee"> </span>
<span> <img id="imgProduct_3" class="SmPrdImg selected"     
onclick="(some javascript);" src="the_src_I_want3.jpg" alt="woohee"> </span>

the only problem is that the exact same code listed above is duplicated way lower in the source. Is there a way to ignore or delete the duplicates using only regex?

  • 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-09T23:04:06+00:00Added an answer on June 9, 2026 at 11:04 pm

    Your pattern’s not very good; it’s way too specific to your exact source code as it currently exists. As @Truth commented, if that changes, you’ll break your pattern. I’d recommend something more like this:

    <img[^>]*src=['"]([^'"]*)['"]
    

    That will match the contents of any src attribute inside any <img> tag, no matter how much your source code changes.

    To prevent duplicates with regex, you’ll need lookahead, and this is likely to be very slow. I do not recommend using regex for this. This is just to show that you could, if you had to. The pattern you would need is something like this (I tested this using Notepad++’s regex search, which is based on PCRE and more robust than JavaScript’s, but I’m reasonably sure that JavaScript’s regex parser can handle this).

    <img[^>]*src=['"]([^'"]*)['"](?!(?:.|\s)*<img[^>]*src=['"]\1['"])
    

    You’ll then get a match for the last instance of every src.

    The Breakdown

    For illustration, here’s how the pattern works:

    <img[^>]*src=['"]([^'"]*)['"]
    

    This makes sure that we are inside a <img> tag when src comes up, and then makes sure we match only what is inside the quotes (which can be either single or double quotes; since neither is a legal character in a filename anyway we don’t have to worry about mixing quote types or escaped quotes).

    (?!
        (?:
            .
        |
            \s
        )*
        <img[^>]*src=['"]\1['"]
    )
    

    The (?! starts a negative lookahead: we are requiring that the following pattern cannot be matched after this point.

    Then (?:.|\s)* matches any character or any whitespace. This is because JavaScript’s . will not match a newline, while \s will. Mostly, I was lazy and didn’t want to write out a pattern for any possible line ending, so I just used \s. The *, of course, means we can have any number of these. That means that the following (still part of the negative lookahead) cannot be found anywhere in the rest of the file. The (?: instead of ( means that this parenthetical isn’t going to be remembered for backreferences.

    That bit is <img[^>]*src=['"]\1['"]. This is very similar to the initial pattern, but instead of capturing the src with ([^'"]*), we’re referencing the previously-captured src with \1.

    Thus the pattern is saying "match any src in an img that does not have any img with the same src anywhere in the rest of the file," which means you only get the last instance of each src and no duplicates.

    If you want to remove all instances of any img whose src appears more than once, I think you’re out of luck, by the way. JavaScript does not support lookbehind, and the overwhelming majority of regex engines that do wouldn’t allow such a complicated lookbehind anyway.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have thousands of HTML files to process using Groovy/Java and I need to

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.