การเตรียมข้อมูล
mysql> CREATE TABLE DemoTable1908 (Code TEXT);
mysql> INSERT INTO DemoTable1908 VALUES
('MySQL(1)Database'), ('MongoDB 2 Database'), ('MySQL(3)Database'),
('SQL Server(10)Database'), ('MySQL 8 Database');
ค้นหา Pattern: MySQL(ตัวเลข)Database
mysql> SELECT * FROM DemoTable1908
WHERE Code REGEXP '^MySQL[(][0-9][)]Database';
ผลลัพธ์:
+------------------+
| Code |
+------------------+
| MySQL(1)Database |
| MySQL(3)Database |
+------------------+
Escape Parentheses ใน Regex
| ตัวอักษร | Escape Method | หมายเหตุ |
|---|---|---|
| ( | [(] หรือ \( | Character Class หรือ Backslash |
| ) | [)] หรือ \) | Character Class หรือ Backslash |
| [ ] | [[], []] | ใน Character Class |
| .*+?^$| | \. \* ฯลฯ | Backslash ทั่วไป |