Mysql
 SQL >> Database >  >> RDS >> Mysql

Come funziona la funzione REGEXP_SUBSTR() in MySQL

La funzione REGEXP_SUBSTR() restituisce la sottostringa che corrisponde a un'espressione regolare. Se non trova corrispondenze, restituisce NULL.

Sintassi

REGEXP_SUBSTR(expr, pat[, pos[, occurrence[, match_type]]])

Esempi

SELECT REGEXP_SUBSTR('Thailand or Cambodia', 'l.nd'); restituisce land.

SELECT REGEXP_SUBSTR('Lend for land', '^C'); restituisce NULL.

Con posizione iniziale:

SELECT REGEXP_SUBSTR('Cat Cut Cot', 'C.t', 2);

Risultato: Cut.

Con occorrenza:

SELECT REGEXP_SUBSTR('Cat Cut Cot', 'C.t', 1, 3);

Risultato: Cot.

Match type

Il parametro match_type permette di controllare sensibilità a maiuscole/minuscole e altri comportamenti. Valori comuni: c, i, m, n, u.