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

3 Answers

  1. Jackson- Reply

    2019-11-14

    + 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

    2019-11-14

    Make your regex ungreedy:

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

    or:

    /<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>