Friday, October 24, 2025
HomeLanguagesPHP mb_ereg_match() Function

PHP mb_ereg_match() Function

The mb_ereg_match() is an inbuilt function in PHP that is used for matching multibyte strings using regular expressions.

Syntax:

mb_ereg_match(pattern, string, options = null): bool

Parameters: This function has 3 parameters:

  • pattern:  The pattern parameters define the regular expression
  • string: This parameter match or is evaluated by the regular expression pattern.
  • option: This parameter defines search regular options.

Return Value: This function returns “true” for matching the string with the regular expression otherwise it will return “false”.

Example 1: The following code demonstrates the PHP mb_ereg_match() function.

PHP




<?php
$email = "dachman@gmail.com";
$pattern =
    '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$';
 
if (mb_ereg_match($pattern, $email)) {
    echo "The email address is valid.";
} else {
    echo "The email address is invalid.";
}
?>


Output:

The email address is valid.

Example 2: The following code is another example of the mb_ereg_match() function of PHP.

PHP




<?php
 
$name = "GeekforGeeks";
 
// Match Only Characters
$pattern = '^[a-zA-Z]+$';
 
if (mb_ereg_match($pattern, $name)) {
    echo "The name is valid.";
} else {
    echo "The name is invalid.";
}
?>


Output:

The name is valid.

Reference: https://www.php.net/manual/en/function.mb-ereg-match.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS