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

  • Home
  • SEARCH
  • 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 3805390
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:40:14+00:00 2026-05-19T14:40:14+00:00

Hi I have the following code and I only want to pull out links

  • 0

Hi I have the following code and I only want to pull out links that have www. in them

<p> Text < href="http://url.com/link/">link text</a> more text < href="http://www.anotehrurl.com/">more link text</a> and < href="http://www.anotherurl.com/sub/sub/link.html">link text</a>. more text < href="http://keepurl.co.uk/link/">link text</a> more text < href="http://www.anotherurl.com/sub/sub/link.html">link text</a>. < href="http://www.anotherurl.com/sub/sub/link.html">link text</a>.  < href="http://www.anotehrurl.com/">more link text</a></p>

im using the reg expression:

(<a href="http:\/\/www.[\d\D]*?\/">([\d\D]*?)<\/a>)

basically I want to match any link that starts with www and not match any link that is keepurl.co.uk/…….

I have put this through rubular and come out with following:

{
Result 1

1.< href=”http://www.anotehrurl.com/&#8221;>more link text
2.more link text
Result 2

1.< href=”http://www.anotherurl.com/sub/sub/link.html&#8221;>link text. more text
< href=”http://keepurl.co.uk/link/&#8221;>link text
2.link text
Result 3

1.< href=”http://www.anotherurl.com/sub/sub/link.html&#8221;>link text. < href=”http://www.anotherurl.com/sub/sub/link.html&#8221;>link text. < href=”http://www.anotehrurl.com/&#8221;>more link text
2.more link text
}

as u can see its pulling out more than i want.

cheers

  • 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-19T14:40:14+00:00Added an answer on May 19, 2026 at 2:40 pm

    What about this:

           <?php
            $html = <<<END
       <p> Text < href="http://url.com/link/">link text</a> more text
           < href="http://www.anotehrurl.com/">more link text</a>
           and < href="http://www.anotherurl.com/sub/sub/link.html">link text</a>.
           more text < href="http://keepurl.co.uk/link/">link text</a> more text
           < href="http://www.anotherurl.com/sub/sub/link.html">link text</a>.
           < href="http://www.anotherurl.com/sub/sub/link.html">link text</a>.
           < href="http://www.anotehrurl.com/">more link text</a></p>
    END;
    
    
            $r = '#href=\"http://(www\.[^\"]*)\">(.+)</#iU';
    
            preg_match_all($r, $html, $m);
    
            var_dump($m[1]);
            var_dump($m[2]);
            ?>
    

    OUTPUT:

    array
      0 => string 'www.anotehrurl.com/' (length=19)
      1 => string 'www.anotherurl.com/sub/sub/link.html' (length=36)
      2 => string 'www.anotherurl.com/sub/sub/link.html' (length=36)
      3 => string 'www.anotherurl.com/sub/sub/link.html' (length=36)
      4 => string 'www.anotehrurl.com/' (length=19)
    array
      0 => string 'more link text' (length=14)
      1 => string 'link text' (length=9)
      2 => string 'link text' (length=9)
      3 => string 'link text' (length=9)
      4 => string 'more link text' (length=14)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I change the following bit of code so that I only have
I have the following code which works fine. However, I only want to return
I have the following code that selects all the different template files out of
I have the following scenario. The client code only has access to FooHandler, not
I have written the following code. But it is removing only &nbsp; not <br>
I have multiple messages in SQS. The following code always returns only one, even
In following code, I have one large component, and I'd like only the level4
I have the following code that makes sure inputs on forms aren't blank, however
I have the following code: string filterTerm = txtDocFilterTerm.Text.ToLower(); var regEx = new Regex(filterTerm);
I have following code in WPF XAML and want it to be converted 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.