php-regexHow to use regex in PHP to match cyrillic characters?
To use regex in PHP to match cyrillic characters, you can use the preg_match()
function. This function takes two parameters: a regular expression and a string to match against. The regular expression should include the cyrillic characters you want to match.
For example, to match any cyrillic characters, you can use the following code:
$string = 'Привет, мир!';
if (preg_match('/[\p{Cyrillic}]/u', $string)) {
echo 'Matched cyrillic characters!';
}
This will output:
Matched cyrillic characters!
The code consists of the following parts:
$string = 'Привет, мир!';
- this sets the string to match against.preg_match('/[\p{Cyrillic}]/u', $string)
- this is the regular expression used to match cyrillic characters. The/u
modifier is used to make the regular expression Unicode-aware.echo 'Matched cyrillic characters!';
- this is the output when the regular expression matches.
For more information, see the PHP documentation on preg_match() and Unicode character classes.
More of Php Regex
- How to use PHP regex to match a nbsp HTML whitespace?
- How to use an "or" condition in PHP regex?
- How to use PHP regex to get a YouTube video ID?
- How to match a space using PHP regex?
- How to use PHP regex to match a zip code?
- How to use PHP regex to match an exact string?
- How to use PHP regex to match special characters?
- How to use PHP regex with the "x" modifier?
- How to use PHP regex to match whitespace?
- How to use PHP regex to match a year?
See more codes...