Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Regex question

  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    Regex question

    I need to match the "Health" in the following line. I have more lines that I need to match they all follow the same pattern but of course the links change.

    PHP Code:
    <li><class="subtle" href="/dir/?link=list&sid=396545018">Health</a></li

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Jacobb123 View Post
    I need to match the "Health" in the following line. I have more lines that I need to match they all follow the same pattern but of course the links change.

    PHP Code:
    <li><class="subtle" href="/dir/?link=list&sid=396545018">Health</a></li
    Code:
    /<a class="[^>]+>([^<]+)/
    best regards

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    There is also a strip_tags function which would work:
    PHP Code:
    <?php
    $text
    ='<li><a class="subtle" href="/dir/?link=list&sid=396545018">Health</a></li>';
    $word=strip_tags($text);

    echo 
    $word;
    ?>

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for the advice. I have another question related to this.

    After using the regex and preg_match_all it matches the strings I need but also some that I don't want.

    I am trying to scrape category listings from a site. All the categories are listed between <UL></UL> tags I only want to match the lines inside the <UL> tags. Is this possible?

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Jacobb123 View Post
    Thanks for the advice. I have another question related to this.

    After using the regex and preg_match_all it matches the strings I need but also some that I don't want.

    I am trying to scrape category listings from a site. All the categories are listed between <UL></UL> tags I only want to match the lines inside the <UL> tags. Is this possible?
    Code:
    /<ul>([^<]+)/m
    all this can't help you if don't try to understand how regex work.

    best regards
    Last edited by oesxyl; 01-12-2008 at 12:32 PM.


  •  

    Posting Permissions

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