note 128198 added to regexp.reference.character-classes
| From: | Julian at main dot php dot net | Date: | Wed, 08 Feb 2023 12:48:36 +0000 |
| Subject: | note 128198 added to regexp.reference.character-classes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220155@lists.php.net to get a copy of this message | ||
Examples with Character classes
<?php
$stringA = "1 In the beginning God created the heavens and the earth.";
$stringB = preg_replace('/[[:^alnum:]]/', '', $stringA); // string(46)
"1InthebeginningGodcreatedtheheavensandtheearth"
$stringC = preg_replace('/[[:^alpha:]]/', '', $stringA); // string(45)
"InthebeginningGodcreatedtheheavensandtheearth"
$stringD = preg_replace('/[[:^ascii:]]/', '', "Pokémon"); //
string(6) "Pokmon"
$stringE = preg_replace('/[[:^blank:]]/', '*', $stringA); // string(57) "*
** *** ********* *** ******* *** ******* *** *** ******"
$stringF = preg_replace('/[[:blank:]]/', '-', $stringA); // string(57)
"1-In-the-beginning-God-created-the-heavens-and-the-earth."
$stringG = sprintf("Vertical Tabulation: %s", chr(11)); // string(22) "Vertical
Tabulation: "
$stringH = preg_replace('/[[:cntrl:]]/', '', $stringG); // string(21)
"Vertical Tabulation: "
$stringLengthG = strlen($stringG); // int(22)
$stringLengthH = strlen($stringH); // int(21)
$stringI = preg_replace('/[[:digit:]]/', '', 'My age is 35');
//string(10) "My age is "
$stringJ = preg_replace('/[[:^digit:]]/', '', 'My age is 35'); //
string(2) "35"
$stringK = preg_replace('/[[:^graph:]]/', '', $stringG); // string(19)
"VerticalTabulation:"
$stringL = preg_replace('/[[:graph:]]/', '', $stringG); // string(3) "
"
$stringM = preg_replace('/[[:lower:]]/', '', $stringG); // string(6) "V T:
"
$stringN = preg_replace('/[[:^lower:]]/', '', $stringG); // string(16)
"erticalabulation"
$stringO = preg_replace('/[[:^print:]]/', '', $stringG); // string(21)
"Vertical Tabulation: "
$stringP = preg_replace('/[[:print:]]/', '', $stringG); // string(1)
""
$stringQ = preg_replace('/[[:punct:]]/', '', $stringG); // string(21)
"Vertical Tabulation "
$stringR = preg_replace('/[[:^punct:]]/', '', $stringG); // string(1)
":"
$stringS = preg_replace('/[[:space:]]/', '', $stringG); // string(19)
"VerticalTabulation:"
$stringT = preg_replace('/[[:^space:]]/', '', $stringG); // string(3) "
"
$stringU = preg_replace('/[[:upper:]]/', '', $stringG); // string(20)
"ertical abulation: "
$stringV = preg_replace('/[[:^upper:]]/', '', $stringG); // string(2)
"VT"
$stringW = preg_replace('/[[:word:]]/', '', $stringG); // string(4) " :
"
$stringX = preg_replace('/[[:^word:]]/', '', $stringG); // string(18)
"VerticalTabulation"
$stringY = preg_replace('/[[:xdigit:]]/', '',
'abcdefghijklmnopqrstuvwxyz0123456789'); // string(20) "ghijklmnopqrstuvwxyz"
$stringZ = preg_replace('/[[:^xdigit:]]/', '',
'abcdefghijklmnopqrstuvwxyz0123456789'); // string(16) "abcdef0123456789"
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.241 (proxied: 2a02:58:14d:5100:189d:7b7b:a4ed:5b00)
----
Manual Page -- https://php.net/manual/en/regexp.reference.character-classes.php
Edit -- https://main.php.net/note/edit/128198
Del: integrated -- https://main.php.net/note/delete/128198/integrated
Del: useless -- https://main.php.net/note/delete/128198/useless
Del: bad code -- https://main.php.net/note/delete/128198/bad+code
Del: spam -- https://main.php.net/note/delete/128198/spam
Del: non-english -- https://main.php.net/note/delete/128198/non-english
Del: in docs -- https://main.php.net/note/delete/128198/in+docs
Del: other reasons-- https://main.php.net/note/delete/128198
Reject -- https://main.php.net/note/reject/128198
Search -- https://main.php.net/manage/user-notes.php