Forum Moderators: coopster
Keep the // comments
To use an example simple uncomment each wider block delimited by /* */
It is quite true that reading the regexp like reading a textual sentence tremendously help your understanding
Like “ allow any text starting with a zero and ending by a dot”
<?
// " '.aaa' " means that any text followed by aaa
/* $test="sssssssssssaaa";
if (preg_match (" '.aaa' ",$test) )
{echo"OK";}else {echo"NO"; }*/
// " '[suy]aaa' " Will match any text containing s u y followed by aaa
/* $test="ssussysssssssaaa";
if (preg_match (" '[suy]aaa' ",$test) )
{echo"OK";}else {echo"NO"; } */
// " '[suy]aaa$ ' Will match any text starting by s u y followed by aaa and ending after aaa
/* $test="suyaaa bbbbbbbbbbbb";
if (preg_match ("'[suy]aaa'",$test) )
{echo"OK";}else {echo"NO"; } */
// /^[a-z]uzz$/ Will match any text starting by that any letter followed by uzz and ending after uzz
// ^ = start of line $ = end of line
/* $test="suzz";
if (preg_match (" /^[a-z]uzz$/",$test) )
{echo"OK";}else {echo"NO"; } */
// /^[0-9]*[a-z]+$/ Starts by numbers followed by letters and end of line
// * means 0 or any recurring occurrences
// + means 1 or any recurring occurrences
/* $test= "123asd";
if (preg_match ("/^[0-9]*[a-z]+$/",$test) )
{echo"OK";}else {echo"NO"; }
// The same with? means optional example: optional underscore _
// /^[0-9]+[a-z]*_?$/ */
// Parentheses group together expression ex: ([a-z][0-9])
// Square brackets define a character-class; within those brackets one may declare a range. Ex: [af] that accepts any letters between a and f:abcdef
// ^ it also could be used to negate ex [^a-z5-9] means NO lower case and not allowing any of 5 6 7 8 or 9
// (A) adding { } ex: /^[a-zA-Z]*[0-9]{2,4}$/
// Means occurrences of letters followed by numbers ought to occur a minimum of 2 times to a max of 4 times
// (B) adding { } ex: /^[a-zA-Z0-9]{2,4}$/
// Means occurrences of letters and numbers ought to occur a minimum of 2 times to a max of 4 times
// could be used for PW (A)
/* $test= "12ab";
if (preg_match ("/^[0-9]*[a-z]{2,4}+$/",$test) )
{echo"OK";}else {echo"NO"; } */ // note if starts by letters = results "NO"
// could be used for PW (B)
$test= "a1Z2";
if (preg_match ("/^[0-9a-zA-Z]{2,4}+$/",$test) )
{echo"OK";}else {echo"NO"; } // note the range of lower and upper cases and numbers allows for that any combo; up to 4 occurrences
?>