note 44274 added to ref.pcre
| From: | steve at stevedix dot de | Date: | Tue, 20 Jul 2004 09:18:00 +0000 |
| Subject: | note 44274 added to ref.pcre | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73673@lists.php.net to get a copy of this message | ||
Something to bear in mind is that regex is actually a declarative programming language like prolog :
your regex is a set of rules which the regex interpreter tries to match against a string. During
this matching, the interpreter will assume certain things, and continue assuming them until it comes
up against a failure to match, which then causes it to backtrack. Regex assumes "greedy
matching" unless explicitly told not to, which can cause a lot of backtracking. A general rule
of thumb is that the more backtracking, the slower the matching process.
It is therefore vital, if you are trying to optimise your program to run quickly (and if you
can't do without regex), to optimise your regexes to match quickly.
I recommend the use of a tool such as "The Regex Coach" to debug your regex strings.
http://weitz.de/files/regex-coach.exe (Windows
installer) http://weitz.de/files/regex-coach.tgz
(Linux tar archive)
----
Manual Page -- http://www.php.net/manual/en/ref.pcre.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44274
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44274&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44274&report=yes
Search -- http://master.php.net/manage/user-notes.php