Writing better regex expression for not using lazy repeat quantifier
问题 I have a regular expression: (<select([^>]*>))(.*?)(</select\s*>) Since it uses lazy repeat quantifier, for longer strings(having options more than 500) it backtracks for more than 100,000 times and fails. Please help me to find a better regular expression which doesn't use lazy repeat quantifier 回答1: <select[^>]*>[^<]*(?:<(?!/select>)[^<]*)*</select> ...or in human-readable form: <select[^>]*> # start tag [^<]* # anything except opening bracket (?: # if you find an open bracket <(?!/select>)