note 68872 added to function.preg-match-all
| From: | cp at ltur dot de | Date: | Mon, 14 Aug 2006 12:56:02 +0000 |
| Subject: | note 68872 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115891@lists.php.net to get a copy of this message | ||
To Stabby at somewhere dot invalid,
i guess you're not very familar with regexps. Here is the working version:
<?php
$pattern='/fred(.+)bloggs/isU';
$data="fred hello\nthere bloggs fred goodbye bloggs";
preg_match_all($pattern,$data,$repTxt,PREG_PATTERN_ORDER);
print_r($repTxt);
?>
1. You have to set the 's' modifier, to make the '.' match newlines (see
documentation)
2. if you write the capuring phrase like you did (.)+ it will capture a lot of single characters. If
you change it to (.+) it will capture all allowed charakters.
HTH
Claus
----
Server IP: 217.160.72.57
Probable Submitter: 213.144.19.2 (proxied: 10.49.115.105)
----
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/function.preg-match-all.php
Edit -- https://master.php.net/note/edit/68872
Del: integrated -- https://master.php.net/note/delete/68872/integrated
Del: useless -- https://master.php.net/note/delete/68872/useless
Del: bad code -- https://master.php.net/note/delete/68872/bad+code
Del: spam -- https://master.php.net/note/delete/68872/spam
Del: non-english -- https://master.php.net/note/delete/68872/non-english
Del: in docs -- https://master.php.net/note/delete/68872/in+docs
Del: other reasons-- https://master.php.net/note/delete/68872
Reject -- https://master.php.net/note/reject/68872
Search -- https://master.php.net/manage/user-notes.php