-3

Can anyone explain this regular expression? This query is used in Oracle to returns the last name for those employees with a double vowel (where last_name contains two adjacent occurrences of either a, e, i, o, or u, regardless of case):

SELECT last_name
FROM employees
WHERE REGEXP_LIKE (last_name, '([aeiou])\1', 'i');

The output is :

LAST_NAME
---------------
De Haan
Greenberg
Khoo
Gee
Greene
Lee
Bloom
Feeney
Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
Ankit Juneja
  • 49
  • 1
  • 5
  • See https://regex101.com/r/EuTfil/1, explanation is on the right. – Wiktor Stribiżew Jan 30 '18 at 08:26
  • Ok, see 1) [Carets in Regular Expressions](https://stackoverflow.com/questions/16944357/carets-in-regular-expressions), 2) [Have trouble understanding capturing groups and back references](https://stackoverflow.com/questions/21880127/have-trouble-understanding-capturing-groups-and-back-references) – Wiktor Stribiżew Jan 30 '18 at 08:50

1 Answers1

0

The regex pattern ([aeiou])\1 simply matches two vowels in succession:

([aeiou])   match and capture a single vowel
\1          then match the same vowel we just captured

If you examine the matching last names, you will see that they all have repeating vowels in some position. By the way, the term \1 is known as a backreference, which refers to a captured quantity earlier in the pattern.

Explore the helpful demo below to better understand how the pattern works.

Demo

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263