note 112352 added to regexp.reference.assertions
| From: | php at mattjanssen dot com | Date: | Wed, 05 Jun 2013 21:38:05 +0000 |
| Subject: | note 112352 added to regexp.reference.assertions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195081@lists.php.net to get a copy of this message | ||
An example of replacing all but the first four and last four characters of a string (or digits of a
credit card number):
preg_replace('/(?<!^|^.|^..|^...).(?!.{0,3}$)/', '*',
'1234567890123456'); // 1234********3456
Notice how the lookbehind requires a non-nested fixed-width expression, while the lookahead is OK
with the {0,3} varied width.
----
Server IP: 69.147.83.199
Probable Submitter: 204.62.150.2
----
Manual Page -- http://php.net/manual/en/regexp.reference.assertions.php
Edit -- https://master.php.net/note/edit/112352
Del: integrated -- https://master.php.net/note/delete/112352/integrated
Del: useless -- https://master.php.net/note/delete/112352/useless
Del: bad code -- https://master.php.net/note/delete/112352/bad+code
Del: spam -- https://master.php.net/note/delete/112352/spam
Del: non-english -- https://master.php.net/note/delete/112352/non-english
Del: in docs -- https://master.php.net/note/delete/112352/in+docs
Del: other reasons-- https://master.php.net/note/delete/112352
Reject -- https://master.php.net/note/reject/112352
Search -- https://master.php.net/manage/user-notes.php