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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:15:18+00:00 2026-06-05T05:15:18+00:00

I’m looking to modify the RegEx pattern below to match items stored between the

  • 0

I’m looking to modify the RegEx pattern below to match items stored between the quote marks of the href property of a link tag:

My conditions are:

  • It can be any URL starting http
  • It must not match anything containing $$

My Current Regular Expression:

var pattern = @"(?<name>href)=""(?<value>http[^""]*)"""; 

Any help would be appreciated.

  • 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-05T05:15:21+00:00Added an answer on June 5, 2026 at 5:15 am

    Try the following expression:

    (?i)href\s*=\s*"http://(?>((?<InvalidUrlChars>[$]{2})|[^"])*?")(?(InvalidUrlChars)(?!))
    

    EDIT: A more detailed explanation of the above pattern:

    (?i) – This is an in-line regular expression option. It sets the expression to be non-case-sensitive. (So that “http” will match “HTTP”)

    (?>…) – This is an atomic grouping construct. It basically says that whatever is matched by the group cannot be unmatched. Regex will try many different paths to see if it can get a match. For example, the construct I’ve used to eliminate matches containing “$$” would be circumvented without this grouping construct.

    (?…) – A named group.

    [^”] – Matches any character that is not a quotation mark.

    (…|…) – An alternate grouping construct. The regex will attempt to find a match using the pattern before the pipe (“|”). If a match cannot be made, it will try again with the pattern following the pipe.

    ? – This is a non-greedy match. With a regular ““, the regex will attempt to match as much as possible. “*?” will attempt to match as little as possible. It is marginally more efficient and helpful when trying to match text between a given set of symbols.

    (?(InvalidUrlChars)…|…) – An if/else grouping construct. Using this particular syntax, the expression preceding the pipe will be matched if the named group (“(InvalidUrlChars)”) was matched. The expression following the pipe will be matched otherwise. The “else” part is optional (I did not use it).

    (?!) – A negative lookahead assertion. I don’t have enough room to describe lookaround assertions, but suffice to say that this expression will always fail.

    So, in summary, this expression will match any URL, but if the URL contains double dollar signs (“$$”) then the InvalidUrlChars group will trigger as “matched”. At the end of the expression, if the InvalidUrlChars group was matched, then the entire match will fail and the atomic group will prevent the Regex from going back and treating the dollar signs as non-quotation marks.

    See http://msdn.microsoft.com/en-us/library/az24scfc for more information

    Compare the following strings:

    <a href="http://test.com"/>
    <a href="http://test.com" alt="test"/>
    <a alt="$$" href="http://test.com"/>
    <a HREF="HTTP://test.com"/>
    <a href=http://test.com />
    <a href="https://test.com"/>
    <a href="ftp://test.com"/>
    <a href="test.com"/>
    <a href="http://test$$.com"/>
    <a href="http://////invalid*&amp;^%$#@!;"/>
    

    The following will match:

    href="http://test.com"
    href="http://test.com"
    href="http://test.com"
    HREF="HTTP://test.com"
    href="http://////invalid*&amp;^%$#@!;"
    

    EDIT: I heartily agree that processing HTML is best done with an HTML parser. Regex is terrible at it. But if you need a rapid fire solution and you don’t care too much about the occasional quirk, Regex is a suitable stand-in.

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

Sidebar

Related Questions

I'm having trouble keeping the paragraph square between the quote marks. In firefox the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a bunch of posts stored in text files formatted in yaml/textile (from
I would like to count the length of a string with PHP. The string
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.