I learn regular, why does this code return false?

$pol = '*'; $a = preg_match('[*\/\-+]',$pol); var_dump($a); 

Here, for some reason, this template works fine for this line: http://www.rubular.com/ What is the problem?

The essence of the regular, check for validity arithmetic signs that come in the input. The template seems correct, I do not understand.

    1 answer 1

    Because PHP allows you to use multiple pair and single delimiters in a regular expression. For example, all of the following regular expressions are the same:

     [regex] /regex/ (regex) @regex@ #regex# 

    Full list of delimiters

    In your case, square quotes are not a character class, but a separator.

     [*\/\-+]ui 

    tantamount to

     @*\/\-+ @ui 
    • Well equivalent to what? Why false if the pattern is correct? I do not understand. - butteff
    • one
      Because the regular expression * \ / \ - + Means: Quantifier * at the beginning of the regular expression (error) Slash / Dash sign - one or more times. - ReinRaus
    • Template # [* \ / \ - +] # ui - turned out to be working. Thanks for the help. - butteff
    • Not at all :-) Just try to understand why it happened, otherwise your next question will be what kind of error. > Unknown modifier [letter] - ReinRaus