Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to match any single character in a string using regular expression with PHP

1 Answer

0 votes
// We need a period (.) in preg_match regular expression to matches any single character

echo preg_match("/b.d/", "bud") . "\n"; // returns true (1)
echo preg_match("/b.d/", "bid") . "\n"; // returns true (1)
echo preg_match("/b.d/", "bed") . "\n"; // returns true (1)
echo preg_match("/b.d/", "b d") . "\n"; // returns true (1)
echo preg_match("/b.d/", "bat") . "\n"; // returns false (0)
echo preg_match("/b.d/", "bd") . "\n"; // returns false (0)
echo preg_match("/b.d/", "bead") . "\n"; // returns false (0)
echo preg_match("/ab.dx/", "ab.dx") . "\n"; // returns false (1)



/*
run:

1
1
1
1
0
0
0
1

*/


answered May 10, 2014 by avibootz
edited Feb 15, 2025 by avibootz
...