- MariaDB - Useful Functions
- MariaDB - Backup Loading Methods
- MariaDB - Backup Methods
- MariaDB - SQL Injection Protection
- MariaDB - Managing Duplicates
- MariaDB - Sequences
- MariaDB - Table Cloning
- MariaDB - Temporary Tables
- Indexes & Statistics Tables
- MariaDB - Alter Command
- MariaDB - Transactions
- MariaDB - Regular Expression
- MariaDB - Null Values
- MariaDB - Join
- MariaDB - Order By Clause
- MariaDB - Like Clause
- MariaDB - Delete Query
- MariaDB - Update Query
- MariaDB - Where Clause
- MariaDB - Select Query
- MariaDB - Insert Query
- MariaDB - Drop Tables
- MariaDB - Create Tables
- MariaDB - Data Types
- MariaDB - Select Database
- MariaDB - Drop Database
- MariaDB - Create Database
- MariaDB - Connection
- MariaDB - PHP Syntax
- MariaDB - Administration
- MariaDB - Installation
- MariaDB - Introduction
- MariaDB - Home
MariaDB Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MariaDB - Regular Expression
Beyond the pattern matching available from LIKE clauses, MariaDB offers regular expression-based matching through the REGEXP operator. The operator performs pattern matching for a string expression based on a given pattern.
MariaDB 10.0.5 introduced PCRE Regular Expressions, which dramatically increases the scope of matching into areas pke recursive patterns, look-ahead assertions, and more.
Review the use of standard REGEXP operator syntax given below −
SELECT column FROM table_name WHERE column REGEXP [PATTERN] ;
REGEXP returns 1 for a pattern match or 0 in the absence of one.
An option for the opposite exists in the form of NOT REGEXP. MariaDB also offers synonyms for REGEXP and NOT REGEXP, RLIKE and NOT RLIKE, which were created for compatibipty reasons.
The pattern compared can be a pteral string or something else such as a table column. In strings, it uses C escape syntax, so double any “” characters. REGEXP is also case-insensitive, with the exception of binary strings.
A table of possible patterns, which can be used are given below −
Sr.No | Pattern & Description |
---|---|
1 |
^ It matches the start of the string. |
2 |
$ It matches the string s end. |
3 |
. It matches a single character. |
4 |
[...] It matches any character in the brackets. |
5 |
[^...] It matches any character not psted in the brackets. |
6 |
p1|p2|p3 It matches any of the patterns. |
7 |
* It matches 0 or more instances of the preceding element. |
8 |
+ It matches 1 or more instances of the preceding element. |
9 |
{n} It matches n instances of the preceding element. |
10 |
{m,n} It matches m to n instances of the preceding element. |
Review the pattern matching examples given below −
Products starting with “pr” −
SELECT name FROM product_tbl WHERE name REGEXP ^pr ;
Products ending with “na” −
SELECT name FROM product_tbl WHERE name REGEXP na$ ;
Products starting with a vowel −
SELECT name FROM product_tbl WHERE name REGEXP ^[aeiou] ;Advertisements