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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:20:10+00:00 2026-06-17T13:20:10+00:00

I have been messing around with Regex for a couple hours now and I’m

  • 0

I have been messing around with Regex for a couple hours now and I’m at an impass. Lets say I have this:

<a href="/link here/faqs"></a><a href="/link/here/contacts"></a><a href="/link here/faqs">

And I want to use PHP preg_replace to match and remove the faqs link so all that is left is the contacts link in the middle. How would I do that? I found out how to make it match
<a href and also match /faqs"></a> but the fact that /faqs"></a> is also in the third link then it removes the second link.

And there could be more after that third link so I can’t use an end of line or anything to stop the regex from matching more.

So once again, how do I get it to match the first and match the last, but keep the middle in tack? And remember, there could be other links after the last FAQ and there could be more FAQ links after them. But I want to remove all of the FAQs ones.

As a side note, how would it work if I wanted to remove all the FAQs ones and all the ones named Help as well.

  • 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-17T13:20:11+00:00Added an answer on June 17, 2026 at 1:20 pm

    Using an XML parser might be an overkill here:

    $html = '<a href="/link here/faqs"></a><a href="/link/here/contacts"></a><a href="/link here/faqs">';
    $dom = new DomDocument();
    $dom->loadHtml($html);
    
    $xpath = new DomXPath($dom);
    $links = $xpath->evaluate('//a');
    
    $newHtml = '';
    
    // rebuild html, and leave out any links that contain "faq"
    // in the href attribute
    foreach($links as $link)
      if(strpos($link->getAttribute('href'), 'faq') === false)
        $newHtml .= $dom->saveXml($link);
    
    print $newHtml;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright I've been messing around with this for hours now and I still can't
Have been working on this question for a couple hours and have come close
So, I have been messing around with webservices for a while now, and I
I have been messing around with HtmlUnit for a little bit and particularly this
I have been messing around with this all morning, I know little to nothing
I have been messing around with asp.net for awhile now and always have issues
I've been messing around with this for a few days now, hopefully someone here
I have been messing around with recursion a few hours and just cant get
I have been messing around with webmin and creating vhosts, now normally I would
I have been messing with this for a while now, and decided to post

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.