9951 explained code solutions for 126 technologies


php-regexHow to use regex in PHP to match dot character?


Regex (Regular Expressions) is a powerful tool used to match patterns in strings. In PHP, it can be used to match dot character (.) by using the preg_match() function.

<?php
$string = 'This is a string with a dot character.';
$pattern = '/\./';

if (preg_match($pattern, $string)) {
    echo 'Match found!';
}

Output example

Match found!

Code explanation

  • $string: This is the string that will be searched for the pattern.
  • $pattern: This is the regex pattern used to match the dot character.
  • preg_match(): This is the function used to match the pattern in the string.

Helpful links

Edit this code on GitHub