php-regexHow to use regex in PHP to match any character?
Regex (Regular Expressions) is a powerful tool used to match patterns in strings. In PHP, it can be used to match any character using the . (dot) character.
$string = 'Hello World!';
$pattern = '/H.llo/';
if (preg_match($pattern, $string)) {
    echo 'Match found!';
}
Output example
Match found!
Code explanation
$string = 'Hello World!';- This is the string we are searching in.$pattern = '/H.llo/';- This is the regex pattern we are using to search for. The.(dot) character is used to match any character.preg_match($pattern, $string)- This is the function used to search for the pattern in the string.echo 'Match found!';- This is the output when a match is found.
Helpful links
More of Php Regex
- How to use PHP regex to match a zip code?
 - How to use PHP regex to match an exact string?
 - How to remove a tag from a string using PHP regex?
 - How to use PHP regex to match a nbsp HTML whitespace?
 - How to use PHP regex with zero or more occurrences?
 - How to match a single quote in PHP regex?
 - How to match a double quote in PHP regex?
 - How to match a quotation mark in PHP regex?
 - How to use regex in PHP to match any character including newline?
 - How to use PHP regex to get a YouTube video ID?
 
See more codes...