A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: regexs - preg_replace

  1. #1
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833

    regexs - preg_replace

    Hi,


    I'm trying to filter out links from a webpage but list them at the bottom with this:

    preg_replace('/href="([^"]+)"[^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);

    It works for <a href="index">bleh</a> but how would i write it that it would also work for single quotes: <a href='index'>bleh</a>

    That's the first part.

    For another function I need set a target="_blank" for all links in a given string. Some already have a target, some don't.

    I suck at regex, reading all about it but just don't get it. Thanks for any help!

    Vincent
    SWIS BV

    Last edited by Markp.com on 07-23-2003 at 02:25 AM

  2. #2

    Re: regexs - preg_replace

    Originally posted by Vincent26381
    Hi,


    I'm trying to filter out links from a webpage but list them at the bottom with this:

    preg_replace('/href="([^"]+)"[^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);

    It works for <a href="index">bleh</a> but how would i write it that it would also work for single quotes: <a href='index'>bleh</a>
    not testing this, but try

    preg_replace('/href=["']([^"]+)["'][^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);

    that's a bracket with a quote and an apostraphe (may need to be escaped since you are using apostraphe's to define the string). hypothetically, it should match href="..." or href="...' or href='..." or href='...'

  3. #3
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833
    Thanks!

    Will try
    Vincent
    SWIS BV

    Last edited by Markp.com on 07-23-2003 at 02:25 AM

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center