SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reg Expression Challenge - non-greedy type expression

    I am ready to bang my head against the wall trying to figure out a solution for my needs. Any help would be greatly appreciated by a regex expert.

    What I'm trying to do is match a specific set of content within some tags. Take the example below where i want to match the "content3" within the tag <href=" and STUFF_3

    #
    <href="content1">STUFF_1<href="content2">STUFF_2<href="content3">STUFF_3
    #

    I cannot for the life of me figure out a way to structure a regex that'll capture that. Anything I do goes back to the longest match and non-greedy doesn't work.

    Any help please?

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,398
    Mentioned
    65 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    $subject '<href="content1">STUFF_1<href="content2">STUFF_2<href="content3">STUFF_3';
    preg_match('/<href="([^"]+)">STUFF_3/'$subject$matches);
    echo 
    $matches[1]; 
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •