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
More of Php Regex
- How to use PHP regex to match whitespace?
- How to use PHP regex to match UTF8?
- How to use negative lookahead in PHP regex?
- How to get last matched occurrence in PHP regex?
- How to use PHP regex to match a nbsp HTML whitespace?
- How to match a double quote in PHP regex?
- How to use PHP regex to match an exact string?
- How to use PHP regex with the "x" modifier?
- How to use PHP regex to match an XML tag?
- How to use PHP regex to match UUID?
See more codes...