Search code examples
phpregexpreg-match

What does "." means in regex


hello friends I am new to pattern matching in php.

I tried this code to find text between '@' and 'space'

<?php
    $pattern = "%@(.*?)\s%";
    $string = "this is @test string @match ";
    preg_match_all($pattern, $string, $match);
    echo "<pre>";
    print_r($match);
    echo "</pre>";
    ?>

It works fine no errors... My question is what does "." means in this I know other symbol's meaning like

% is terminaor
( start of substring
) end of substring
* 0 or more match

etc .. but didnt understand the use of "." here.. can any body explain it .and correct me if I am wrong anywhere else

Thanks in advance


Solution

  • . matches any character except for newline characters. In your case it will match anything between @ and a space except for newline characters or it can just be '@ ' since you have .*? which means that it is optional for the wild card .. To have the . to check everything including newline, add s after your delimiter % eg: ...%s s (PCRE_DOTALL)