Current Location: Home> Function Categories> mb_ereg_match

mb_ereg_match

Regular expression matching for multibyte strings
Name:mb_ereg_match
Category:Multi-byte string
Programming Language:php
One-line Description:Use multibyte character-encoded regular expressions to match

Function name: mb_ereg_match()

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

Usage: The mb_ereg_match() function is used to match using a multibyte character-encoded regular expression.

Syntax: mb_ereg_match(string $pattern, string $subject [, string $option = ""]) : bool

parameter:

  • $pattern: The regular expression pattern to match.
  • $subject: The string to search for.
  • $option (optional): A string used to specify matching options. The default is an empty string.

Return value: Return true if the match is successful, otherwise return false.

Example 1:

 $pattern = "正则表达式"; $subject = "这是一个测试字符串"; if (mb_ereg_match($pattern, $subject)) { echo "匹配成功"; } else { echo "匹配失败"; }

Example 2:

 $pattern = "[\x{4e00}-\x{9fa5}]"; // 匹配中文字符$subject = "测试字符串"; if (mb_ereg_match($pattern, $subject)) { echo "匹配成功"; } else { echo "匹配失败"; }

Notes:

  • This function is a simplified encapsulation of the mb_ereg() function, which detects whether the entire string matches the regular expression pattern.
  • Since mb_ereg_match() uses multibyte character encoding, when using this function, you need to make sure that character encoding and internal character encoding have been set correctly.
  • You can use the $option parameter to specify matching options, such as "i" means case insensitive matching, "m" means multi-line matching, etc.
  • For more information about the syntax and matching options of regular expressions, please refer to the official PHP documentation.
Similar Functions
Popular Articles