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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:00:28+00:00 2026-05-25T18:00:28+00:00

$str = ‘href=http://grego.com href=httpxoobar href=xxx href=ZZZZZ’; preg_match_all(‘/http:\/\/(?<!href=)([\s\S]+)/’, $str,$m); print_r($m); I’m trying this code. I

  • 0
$str = 'href="http://grego.com" href="httpxoobar" href="xxx" href="ZZZZZ"';

preg_match_all('/http:\/\/(?<!href=")([\s\S]+)"/', $str,$m);


print_r($m);

I’m trying this code.

I want to create 4 matches, I want to match all the href=” that doesn’t have “http://&#8221; after it, and then get what is inside the href=”(this)” (I’m using \s\S because it may contain new lines) and when it finds a quote ( ” ) it stops and keep fetching the next (that in this case is in the same line),

in this example it should bring all 4 results.

how do I do that? Thanks.

  • 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-25T18:00:28+00:00Added an answer on May 25, 2026 at 6:00 pm

    You’ve got things a bit mixed up.

    • You’ve made http:// part of the match although you’re writing that you don’t want to match it,
    • you’re using a negative lookbehind where a positive one would make sense,
    • you’re not using the /s option to allow the dot to match newlines,
    • you’re using a greedy quantifier that will match too much, and
    • you’re using regexes to match HTML.

    That said, you might get away with this:

    (?<=href=")(?!http://)[^"]+
    

    i. e. in PHP:

    preg_match_all(
        '%(?<=href=") # Assert position right after href="
        (?!http://)   # Assert that http:// is not right ahead
        [^"]+         # Match one or more characters until the next "
        %x', 
        $subject, $result, PREG_PATTERN_ORDER);
    $result = $result[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if(str.contains(final)) { id = Integer.parseInt(str.substring(18, str.length() - 6)); } System.out.println(id); This line of code
string str contains somewhere within it http://www.example.com/ followed by 2 digits and 7 random
char str[] = http://www.ibegroup.com/; char *p = str ; void Foo ( char str[100]){
var str = 'http://maps.google.com/maps?f=d&daddr= 8467 + Perimeter + Rd .+ S + Seattle +
Using str_replace I want to change $url from this: $url = http://example.com/images/lala1.jpg to this
NSString *str = [[NSString alloc]init]; str = [str initWithString:@]; This code crashes. If I
I have this String str = a,pnp,a|pnp,lab2|pnp,a|pnp,lab2,utr,utr; String[] strings = str.split(|); This code won't
This: str = test test ed.selection.setContent(str);//1 Behaves differently than this: ed.selection.setContent(test test);//2 I'm working
var str = This is a string; var thing = str.replace(string,thing); console.log( str )
str = Hello☺ World☹ Expected output is: Hello:) World:( I can do this: str.gsub(☺,

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.