Subtracted in the lessons here is such an example:

<?php $preg = '[az]{4}[0-9]{5}'; $string = 'abcd12345efg'; preg_match($preg, $string, $arr); print_r($arr); ?> 

As I understand it, the pattern '[az] {4} [0-9] {5}' is equal to the pattern: '[az] [az] [az] [az] [0-9] [0-9] [0- 9] [0-9] [0-9] '
How not to twist, as a result I get:

Warning: preg_match () [function.preg-match]: Unknown modifier '{' in C: wwwreg.php on line 6

And such an error occurs when a second pair of curly or square brackets appears.
Tell me, what am I doing wrong here?

    3 answers 3

     $preg = '/[az]{4}[0-9]{5}/'; 
    • one
      here thanks :) - Roman St

    Do not forget to also indicate the beginning and end of the line.

      $ preg = '/ ^ [az] {4} [0-9] {5} $ /'; 
    and then your expressions may work incorrectly in the first case
      343dfsa32134 // true 
    and in the second
      343dfsa32134 // false 
    sometimes it can take a lot of time to understand why a regular program does not work quite correctly

      you can still $ preg = '/ ^ ([a-z0-9] {5,}) $ /';