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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:41:42+00:00 2026-05-13T01:41:42+00:00

I am trying to extract all links that have /thumb/ in it within ‘s.

  • 0

I am trying to extract all links that have /thumb/ in it within “”‘s. Actually i only need to use the images src. I dont know if images will end with jpg or if there will be case sensitivity problems, etc. I really only care about the full link.

m = Regex.Match(page, @"""(.+?/thumbs/.+?)""");
//...
var thumbUrl = m.Groups[1].Value;

My full code

    var page = DownloadWebPage(url);
    var reg = new Regex(@"Elements\s+\((.*)\)", RegexOptions.Multiline);
    var m = reg.Match(page);
    var szEleCount= m.Groups[1].Value;
    int eleCount = int.Parse(szEleCount);

    m = Regex.Match(page, @"""(.+?/thumbs/.+?)""");
    while (m.Success)
    {
        var thumbUrl = m.Groups[1].Value;
        //i break here to see a problem
        m = m.NextMatch();
    }

thumbUrl looks like

center\”> … lot of text, no /thumbs/ … src=\”http://images.fdhkdhfkd.com/thumbs/dfljdkl/22350.jpg

  • 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-05-13T01:41:42+00:00Added an answer on May 13, 2026 at 1:41 am

    The way a reluctant (non-greedy) quantifier works is, once it starts to match, it stops at the first opportunity. What you’re trying to do is match the minimum amount of text that meets your criteria, which isn’t the same thing; you still have to make sure it doesn’t start matching before you want it to. As others have suggested, you can do that by replacing the .+? in your regex with something that doesn’t match quotes, like [^""]+.

    But that still leaves you with a performance problem. In your example, the regex starts matching when it sees the quote in center">; when it reaches the quote at src=" (assuming you’ve changed the .+? to [^""]+) it will abort that match attempt an move on. The next attempt, starting at the quote in src=" will succeed. So you’re getting the right result now, but you’re still wasting a lot of time on that first, failed match attempt.

    The key to writing fast regexes is to make sure that, if a match attempt is going to fail, it fails as quickly as possible. For example, I think it’s safe to assume you don’t want any angle brackets between the " and /thumbs/, so add them to the set of characters you don’t want to match: [^""<>]+. Now, any match attempt starting at the quote in center"> it will be aborted at the very next position.

    There are other things you can do to further optimize the regex, involving atomic groups and negative lookaheads, but this will probably be as fast as you need:

    @"""([^""<>]+/thumbs/[^""<>]+)"""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract all of the links to image files from a text
What I am trying to achieve is to extract all links with a href
hello guys I am trying to extract all the anchor links from aol but
I am trying to extract all substrings in a string that is between the
I have a list of files and I'm trying to extract all layer1_*.grd files.
I have a string that i am trying to extract patterns from, the string
I'm trying to use the nokogiri gem to extract all the urls on the
I'm trying to open a word document and just extract all the text that
I would like to extract all img tags that are within an anchor tag
I'm trying to extract all the unique characters from my utf-8 French dictionary file

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.