Open In App

PHP mb_ereg_search_getregs() Function

Last Updated : 26 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The mb_ereg_search_getregs() function is an inbuilt function in PHP that is used for matching substrings in the last multibyte regular expression match. It can be used after calling mb_ereg_search() or mb_ereg_search_pos() functions.

Syntax:

mb_ereg_search_getregs(): array|false

Parameters: This function does not accept any parameters.

Return Values: This function returns an array of the matched substring in the last multibyte regular expression match. The first element of the array contains the entire matched substring, and the subsequent elements contain the contents of any capturing parentheses in the regular expression. It returns “false” when the error occurs.

Example 1: The following program demonstrates the mb_ereg_serach_getregs() function.

PHP




<?php
$string = "The quick brown fox jumps over the lazy dog";
$pattern = "fox";
mb_regex_encoding("UTF-8");
mb_ereg_search_init($string, $pattern);
if (mb_ereg_search()) {
    $regs = mb_ereg_search_getregs();
    echo "The matched substring is:" . $regs[0];
}
?>


Output:

The matched substring is: fox  

Example 2: The following program demonstrates the mb_ereg_search_getregs() function.

PHP




<?php
$string = "Geeks for Geeks";
$pattern = "[m]";
mb_regex_encoding("UTF-8");
mb_ereg_search_init($string, $pattern);
if (mb_ereg_search()) {
    $regs = mb_ereg_search_getregs();
    echo "The matched substring is: " . $regs[0] . "\n";
} else {
    echo "Match string is not found";
}
?>


Output:

Match string is not found 

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads