regex - regex - Stop at first character match? - answerstu - answerstu

3 Answers

  1. Jackson- Reply


    + is a greedy operator meaning it matches as much as it possibly can and still allows the rest of the regex to match. For this, I recommend using a negated class meaning any character except: " "one or more" times.

    /<a href="ftp:([^"]+)">/

    Live Demo

  2. Jacob- Reply


    Make your regex ungreedy:

    /<a href="ftp:(.+?)">/
    //        here __^


    /<a href="ftp:([^>"]+)">/

    But it's better to use a parser.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>