PHP mb_ereg_search_init() Function Last Updated : 24 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The PHP mb_ereg_search_init() function is an inbuilt function that is used to initialize the multibyte regular expression for a search. It sets the target string and regular expression to be searched using the mb_ereg_search() function. Syntax: bool mb_ereg_search_init( string $string, ?string $pattern = null, ?string $options = null ) Parameters: $string: The string to be searched. This parameter is required.$pattern: The regular expression pattern to be used for the search. It is an optional parameter, and if not specified, the previously set pattern will be used.$options: The search option. This parameter is optional and its default value is "msr" which stands for "multi-byte", "single-line", and "match-start-of-string". The option can be set to "msri" to include a "case-insensitive" match, or "msrx" to include an "extended regular expression" match. Return Value: This method returns "true" on success and "false" on failure. Example 1: The following code shows the working of the PHP mb_ereg_search_init() function. PHP <?php // Declare a string $str = "Welcome to GeeksforGeeks"; // Declare a pattern string $pattern = "GeeksforGeeks"; // Using mb_ereg_search_init() function mb_ereg_search_init($str, $pattern); // Use mb_ereg_search() function for // multibyte regular expression match // for a predefined multibyte string if (mb_ereg_search()) { echo "Pattern Match found"; } else { echo "Pattern Match not found"; } ?> Output: Pattern Match found Example 2: This code also shows the working of the above function. PHP <?php // Declare the search string $str = "Welcome, Geeks!"; // Non-alphanumeric characters $pattern = "\w+"; // Using the mb_ereg_search_init() function to // search the multibyte regular expression mb_ereg_search_init($str, $pattern); // Perform the search and print the results while ($res = mb_ereg_search_regs()) { echo "Match found: " . $res[0] . "\n"; } ?> Output: Match found: Welcome Match found: Geeks Reference: https://www.php.net/manual/en/function.mb-ereg-search-init.php Comment More infoAdvertise with us Next Article PHP mb_ereg_search_getpos() Function B blalverma92 Follow Improve Article Tags : PHP PHP-function PHP-Multibyte-String Similar Reads PHP mb_ereg_search() Function The mb_ereg_search() is a PHP function used to search & match for a regular expression pattern in a string using multi-byte characters. It is similar to preg_match() but works with multi-byte characters. Syntax: mb_ereg_search(?string $pattern = null, ?string $options = null): boolParameters: Th 2 min read PHP mb_ereg_search_getpos() Function The mb_ereg_search_getpos() function is an inbuilt function in PHP that retrieves the start position of the last match and the end position of the last match. It works with multibyte character sets. Syntax: mb_ereg_search_getpos(): int Parameters: This function does not accept any parameters. Return 2 min read PHP mb_ereg_search_getregs() Function 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 fun 1 min read PHP mb_ereg_search_pos() Function The mb_ereg_search_pos() is an inbuilt function in PHP that is used in regular expressions to match a given string. It searches for the first occurrence of a pattern in the string and returns the starting position and the ending position of the match. Syntax:mb_ereg_search_pos( ?string $pattern = nu 2 min read PHP mb_ereg_search_regs() Function The mb_ereg_search_regs() function is an inbuilt function in PHP that is used for regular expressions to match a given string. If the match is found, then it will return the matched part as an array. Syntax: mb_ereg_search_regs( ?string $pattern = null, ?string $options = null): array|falseParameter 2 min read PHP mb_ereg_search_setpos() Function The mb_ereg_search_setpos() function is an inbuilt function in PHP that is used for setting the starting point for the next regular expression that will be matched. Syntax: mb_ereg_search_setpos(int $offset): bool Parameter: This function accepts one parameter that is described below. $offset: This 1 min read Like