简体   繁体   中英

Dot (.) Meta character Php Regex

Dot (.) Meta character is not matching text and showing zero(o) output. Please tell me what i am missing in this code.

$string = 'pakistan';
echo preg_match('/p.n/',$string);

Use below code:-

preg_match("/p.*n/U", $string, $match);   
echo '<pre>'; print_r($match[0]);

If you want to count how many times specific word is repeating in the string

Use preg_match_all

preg_match_all ("/p.*n/U", $string, $match);   
echo '<pre>'; print_r($match[0]);

Hope it will help you :)

The following regex:

$string = 'pakistan';
echo preg_match('~^p.+n$~',$string);

Anchors the string to the beginning and end and requires at least one (but unlimited times) character between p and n .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM