Home  >  Article  >  Database  >  How to use the regexp_substr function in mysql

How to use the regexp_substr function in mysql

WBOY
WBOYforward
2023-05-30 22:40:051864browse

1. Return the substring matching the pattern pat in the string expr. If no matching substring is found, NULL is returned.

2. If expr or pat is NULL, the function returns NULL.

The REGEXP_SUBSTR() function supports the following optional parameters:

pos means starting the search from the specified position of the string expr. By default, matching starts from the first character.

occurence indicates which matching substring is returned. The first matching substring is returned by default.

match_type indicates the matching method, and the parameters are consistent with the above REGEXP_LIKE() function.

Example

mysql> SELECT REGEXP_SUBSTR('abc def ghi', '[a-z]+');
+----------------------------------------+
| REGEXP_SUBSTR('abc def ghi', '[a-z]+') |
+----------------------------------------+
| abc                                    |
+----------------------------------------+
mysql> SELECT REGEXP_SUBSTR('abc def ghi', '[a-z]+', 1, 3);
+----------------------------------------------+
| REGEXP_SUBSTR('abc def ghi', '[a-z]+', 1, 3) |
+----------------------------------------------+
| ghi                                          |
+----------------------------------------------+

The above is the detailed content of How to use the regexp_substr function in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete