
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP – Match regular expression using mb_ereg_match()
In PHP, mb_ereg_match() function is used for matching a given string with a regular expression pattern. This function only matches the string from the beginning of the string and it is not necessary that it will match the string till the end. This function will return true or 1 if a match is found, else it will return False or 0.
Syntax
bool mb_ereg_match(str $pattern, str $string, str $options)
Parameters
It accepts the following three parameters −
$pattern − This parameter is used for the regular expression.
$string − This parameter is being evaluated.
$options − It is used for the search.
Return Values
mb_ereg_match() returns true or 1 if the given string matches the regular expression pattern. If it does not match, then it will return False or 0.
Example 1
<?php //It will return True because H is matched $result = mb_ereg_match("H", "Hello World"); var_dump($result); //It will return Frue because H is not matched $output= mb_ereg_match("H", "World"); var_dump($output); ?>
Output
bool(true) bool(false)
Note − In this example, it will only match the string from the beginning but it is not necessary that it will match the string till the end.
If you want to match the string anywhere in the given string, then you can use the wildcard and repeat operators .*. See the next example.
Example 2
<?php $result = mb_ereg_match(".*e", "Hello World"); var_dump($result); ?>
Output
bool(true)
- Related Articles
- How to match digits using Java Regular Expression (RegEx)
- Match Expression in PHP 8
- Explain Python regular expression search vs match
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- How to match non-digits using Java Regular Expression (RegEx)
- How to match a nonwhitespace character in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- Regular expression to match numbers only in JavaScript?
- How to match parentheses in Python regular expression?
- MongoDB regular expression to match a specific record?
- How to match any one lowercase vowel in python using Regular Expression?
- Program to match vowels in a string using regular expression in Java
- How to match a regular expression against a string?
