/*
There are four main functions in Oracle that support regular expressions:
1,regexp_like: Similar to like function
2,REGEXP_INSTR: Similar to INSTR function
3,REGEXP_SUBSTR: Similar to SUBSTR function
4,regexp_replace: Similar to REPLACE function
They are used in the same usage as Oracle SQL functions like, INSTR, SUBSTR, and replace.
However, they use POSIX regular expressions instead of the old percent semicolon (%) and wildcard (_) characters.
POSIX Regular expressions are composed of standard metacharacters (metacharacters):
' ^ ' matches the start position of the input string, used in a bracket expression, which indicates that the character set is not accepted.
' $ ' matches the end position of the input string. If the Multiline property of the RegExp object is set, the $ also
With '/n ' or '/R '.
'. ' matches any single character except a newline character.
'? ' matches the preceding subexpression 0 times or once.
' + ' matches the preceding subexpression one or more times.
' * ' matches the preceding subexpression 0 or more times.
' | ' indicates a choice between the two items. Example ' ^ ([a-z]+|[ 0-9]+) $ ' represents all lowercase letters or numbers combined
String.
' () ' marks the beginning and end position of a subexpression.
' [] ' marks a bracket expression.
' {m,n} ' an exact number of occurrences,m=< occurrences <=n, ' {m} ' indicates that M times, ' {m,} ' means at least
appear m times.
/num matches num, where num is a positive integer. A reference to the match that was obtained.
Character clusters:
[[: Alpha:]] any letter.
[[:d Igit:]] any number.
[[: Alnum:]] any letter or number.
[[: Space:]] any white character.
[[: Upper:]] any uppercase letter.
[[: Lower:]] any lowercase letter.
[[:p UNCT:]] any punctuation.
[[: Xdigit:]] Any number in 16, equivalent to [0-9a-fa-f].
Operation Precedence for various operators
/Escape character
(), (?:), (? =), [] parentheses and square brackets
*, +,?, {n}, {n,}, {n,m} qualifier
^, $, anymetacharacter position and order
*/
--Create a table
CREATE TABLE Fzq
(
ID varchar (4),
Value varchar (10)
);
--Data insertion
INSERT INTO FZQ values
(' 1 ', ' 1234560 ');
INSERT INTO FZQ values
(' 2 ', ' 1234560 ');
INSERT INTO FZQ values
(' 3 ', ' 1b3b560 ');
INSERT INTO FZQ values
(' 4 ', ' abc ');
INSERT INTO FZQ values
(' 5 ', ' ABCDE ');
INSERT INTO FZQ values
(' 6 ', ' adreasx ');
INSERT INTO FZQ values
(' 7 ', ' 123 45 ');
INSERT INTO FZQ values
(' 8 ', ' ADC de ');
INSERT INTO FZQ values
(' 9 ', ' adc,.de ');
INSERT INTO FZQ values
(' Ten ', ' 1 B ');
INSERT INTO FZQ values
(' Ten ', ' Abcbvbnb ');
INSERT INTO FZQ values
(' 11 ', ' 11114560 ');
INSERT INTO FZQ values
(' 11 ', ' 11124560 ');
--regexp_like
--query value with a record ending with 1 at the beginning of 60 and a length of 7 bits
SELECT * from Fzq where value is like ' 1____60 ';
SELECT * from Fzq where regexp_like (value, ' 1....60 ');
--query value with a record ending with 1 at the beginning of 60 and a length of 7 bits and all numbers.
-Using like is not a good implementation.
SELECT * from Fzq where regexp_like (value, ' 1[0-9]{4}60 ');
--You can also do this by using the character set.
SELECT * from Fzq where regexp_like (value, ' 1[[:d igit:]]{4}60 ');
--Query value is not a pure digit record
SELECT * from Fzq where is not regexp_like (value, ' ^[[:d igit:]]+$ ');
--The query value does not contain any number of records.
SELECT * from Fzq where regexp_like (value, ' ^[^[:d igit:]]+$ ');
--query for records beginning with 12 or 1b. is case-insensitive.
SELECT * from Fzq where regexp_like (value, ' ^1[2b] ', ' I ');
--query for records beginning with 12 or 1b. Case sensitive.
SELECT * from Fzq where regexp_like (value, ' ^1[2b] ');
--The query data contains blank records.
SELECT * from Fzq where regexp_like (value, ' [[: Space:]] ');
--query all records that contain lowercase letters or numbers.
SELECT * from Fzq where regexp_like (value, ' ^ "[a-z]+|[ 0-9]+) $ ');
--Query any records that contain punctuation marks.
SELECT * from Fzq where regexp_like (value, ' [[:p UNCT:]] ');
/*
It's OK to understand its grammar. Other function usages are similar.
*/