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,907 questions

51,839 answers

573 users

How to search for characters that must match the beginning of the string with preg_match in PHP

1 Answer

0 votes
// We need to use the caret (^) at the beginning of a regular expression
 
echo preg_match("/^Info/", "Information, Tools & Social For Your Profession") . "\n"; // true (1)
echo preg_match("/^Info/", "Tools, Information & Social For Your Profession") . "\n"; // false (0)

// It's Case-sensitive
echo preg_match("/^info/", "Information, Tools & Social For Your Profession") . "\n"; // false (0)

   
/*
run:
    
1
0
0
    
*/


answered May 2, 2014 by avibootz
edited Feb 9, 2025 by avibootz
...