Re: OT - Regular Expression
| From: | Arpad Ray | Date: | Fri, 09 Feb 2007 12:44:40 +0000 |
| Subject: | Re: OT - Regular Expression | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248643@lists.php.net to get a copy of this message | ||
Roman Neuhauser wrote:
This shouldn't do too much backtracking, try it out: "*8*" => /^(?:\d*8\d*){4}$/ The {4} in there repeats the subpattern 4 times, rather than limiting it to 4 characters.I really can't think of an elegant to do what you ask with regex - why limit yourself to regex anyway? It would be far simpler to just convert * to .* and check the length separately with strlen(), plus if you check the length first then you don't need regex at all if it fails. Arpad