note 63964 added to reference.pcre.pattern.syntax
| From: | spookatop dot pl at osu1 dot php dot net | Date: | Tue, 04 Apr 2006 18:37:03 +0000 |
| Subject: | note 63964 added to reference.pcre.pattern.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107324@lists.php.net to get a copy of this message | ||
A useful note for beginners: note the difference between mathematical and PHP regular expressions.
The _mathematical_ regex:
(a+b+c)*
which written in PHP syntax will look like:
[abc]*
will match any string built of a, b or c letters, but will not match string, for example:
abcd
However, the _PHP_ regular expression will match above string, because the regex means "accept
all strings, which contain 0 or more occurences of letters: a, b or c".
To convert the regexp from the mathematical to PHP convention, use the ^ and $ characters, which
indicate start and end of tested string. So the regexp:
^[abc]*$
means "match all strings, which, between its beginning and end, have 0 or more occurences of
letters a, b or c" - which is, what we searched for.
Nasty habit, especially after two tests on "theoretical basics of computer science" :)
----
Server IP: 195.136.184.34
Probable Submitter: 87.105.48.179
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
Edit -- http://master.php.net/note/edit/63964
Del: integrated -- http://master.php.net/note/delete/63964/integrated
Del: useless -- http://master.php.net/note/delete/63964/useless
Del: bad code -- http://master.php.net/note/delete/63964/bad+code
Del: spam -- http://master.php.net/note/delete/63964/spam
Del: non-english -- http://master.php.net/note/delete/63964/non-english
Del: in docs -- http://master.php.net/note/delete/63964/in+docs
Del: other reasons-- http://master.php.net/note/delete/63964
Reject -- http://master.php.net/note/reject/63964
Search -- http://master.php.net/manage/user-notes.php