digit (0-9). The qualifier \D matches anything except a digit. Match the a string with the structure xxXxxXxxxx. "x" represents a digit, "X" a non digit. $pattern = '()'; $result = preg_match_all( $pattern, "12.34.5678\n123456789\nab.cd.efgh", $matches ); if ($result && count($matches[0]) == 1) { echo 'SUCCESS'; } else { echo 'FAIL'; } 7 . 2
sure that a linefeed at the end of the subject is not ignored. Validate that the subject is a German zip code. It consists of 5 digits. $pattern = '()'; $subjects = [ '01234' => TRUE, '50670' => TRUE, '40213' => TRUE, 'abcdef' => FALSE, "50670\n" => FALSE, "123456" => FALSE ]; foreach ($subjects as $subject => $shouldMatch) { if ($shouldMatch == preg_match($pattern, $subject)) { echo "SUCCESS\n"; } else { echo "FAIL\n"; } } 8 . 4
two characters. The characters can be digits or a letter between a and f. $pattern = '()'; $subjects = [ '01' => TRUE, '0f' => TRUE, 'FA' => TRUE, 'az' => FALSE, "foo" => FALSE, "123" => FALSE ]; foreach ($subjects as $subject => $shouldMatch) { if ($shouldMatch == preg_match($pattern, $subject)) { echo "SUCCESS\n"; } else { echo "FAIL\n"; } } 9 . 4
you to match a fixed repeat of qualifiers. Validate that the subject is a German zip code. It consists of 5 digits. $pattern = '()'; $subjects = [ '01234' => TRUE, '50670' => TRUE, '40213' => TRUE, 'abcdef' => FALSE, "50670\n" => FALSE, "123456" => FALSE ]; foreach ($subjects as $subject => $shouldMatch) { if ($shouldMatch == preg_match($pattern, $subject)) { echo "SUCCESS\n"; } else { echo "FAIL\n"; } } 10 . 2
extended unicode grapheme sequence \p{ }, \p - character with unicode property \p{^ }, \P{^ } - character without unicode property \p{ } - character from script \x{ } - code point xx x xx xx script FFFF 11 . 1
a title ('Mr.', 'Ms.', 'Mrs.'), followed by a space and a string that contains at least one letter. $pattern = '()'; $subjects = [ 'Mr. Doe' => TRUE, 'Mrs. Jane Doe' => TRUE, 'Ms. Marple' => TRUE, 'Mr. ' => FALSE, "Mrs. 1" => FALSE, "1. Mr. Doe" => FALSE ]; foreach ($subjects as $subject => $shouldMatch) { if ($shouldMatch == preg_match($pattern, $subject)) { echo "SUCCESS\n"; } else { echo "FAIL\n"; } } 13 . 2