Regular Expression Request in Oracle

I'm trying to learn regular expressions in Oracle (rather, my first attempt to do anything with RegEx).

What does the symbol ^at the beginning mean ? The documentation mentions

Use the caret and dollar sign to define patterns that match the start or end of a string.
^ defines that start of a string or column 1 of the string.

So, using '^[*est]'as a template, I understand that match anything which has -est as its ending.

However, when I tried,

SQL> select 1 from dual where regexp_like('test','^[*est]');

         1
----------
         1

SQL>  select 1 from dual where regexp_like('best','^[*est]');

no rows selected

SQL>  select 1 from dual where regexp_like('fest','^[*est]');

no rows selected

Removal ^however, and get

SQL>  select 1 from dual where regexp_like('fest','[*est]');

         1
----------
         1

SQL>  select 1 from dual where regexp_like('best','[*est]');

         1
----------
         1

SQL> select 1 from dual where regexp_like('test','^[*est]');

         1
----------
         1

Why is this so? Why in the first case does a match occur for `test ', but not for others?

+3
source share
2 answers
select 1 from dual where regexp_like('best','^[*est]');

[] in regexps means "any of the listed characters"

Inside, []an asterisk loses its special meaning and means only an asterisk.

regexp , *, e, s t ( , ).

, -est, :

select 1 from dual where regexp_like('nest','est$')

" est, ($)"

+5

Oracle , [] (). [est] "e", "s" "t". (est), , "est".

+2

Source: https://habr.com/ru/post/1728057/


All Articles