!preg_match php code example

Example 1: preg_match in php

<?php
//Syntex : int preg_match( $pattern, $input, $matches, $flags, $offset)
  
// Declare a variable and initialize it 
$str = "Check For Testing."; 
  
// case-Insensitive search for the word "Check" 
if (preg_match("/\bCheck\b/i", $str, $match))  
    echo "Matched!"; 
else
    echo "not matched";   
  

// Output : Matched
?>

Example 2: preg_match

if(!preg_match('/^\[a-zA-Z]+$/',$input)) {
   // String contains not allowed characters ...
}

Example 3: php regex

preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, PREG_OFFSET_CAPTURE);

Tags:

Php Example