Current Location: Home> Function Categories> mb_ereg_search_regs

mb_ereg_search_regs

Returns the matching part of a multibyte regular expression
Name:mb_ereg_search_regs
Category:Multi-byte string
Programming Language:php
One-line Description:Returns the result of the last multibyte regular expression match

Function name: mb_ereg_search_regs()

Applicable version: PHP 4 >= 4.2.0, PHP 5, PHP 7

Usage: The mb_ereg_search_regs() function is used to return the result of the last multibyte regular expression match.

Syntax: mb_ereg_search_regs( [ string $pattern [, string $options = "msr" ]] ) : array|false

parameter:

  • pattern (optional): regular expression pattern. If not provided, use the most recent mode set using the mb_ereg_search_init() function.
  • options (optional): Match options. The default is "msr", which means multi-line mode, single-line mode and reverse search mode.

Return value:

  • If the match is successful, mb_ereg_search_regs() returns an index array containing the results of the subgroup matching. The first element is the complete match result, and the subsequent elements are the subgroup match result stored in parentheses.
  • If no matching result is obtained, false will be returned.

Example:

 $str = "Hello, 你好,世界!"; mb_ereg_search_init($str, '[\x{4e00}-\x{9fa5}]'); mb_ereg_search(); $regs = mb_ereg_search_regs(); print_r($regs);

Output:

 Array ( [0] => 你)

In the above example, we first use the mb_ereg_search_init() function to initialize a multibyte regular expression search and specify the range of Chinese characters to match. Then use the mb_ereg_search() function to perform the search. Finally, by calling the mb_ereg_search_regs() function, we obtain the array of subgroup match results of the matching results, where the first element is the complete match result.

Similar Functions
Popular Articles