Detailed usage of oracle Regular Expression regexp_like

Source: Internet
Author: User

/*
There are four functions that support regular expressions in ORACLE:
1. REGEXP_LIKE: similar to LIKE
2. REGEXP_INSTR: similar to INSTR
3, REGEXP_SUBSTR: similar to SUBSTR
4. REGEXP_REPLACE: similar to REPLACE
They are used in the same way as Oracle SQL functions LIKE, INSTR, SUBSTR, and REPLACE,
However, they use POSIX Regular Expressions instead of the old percent sign (%) and wildcard character.
POSIX regular expressions are composed of standard metacharacters:
'^' Matches the start position of the input string and is used in the square brackets expression. In this case, this character set is not accepted.
'$' Matches the end position of the input string. If the Multiline attribute of the RegExp object is set
'/N' or'/R '.
'.' Matches any single character except the line break.
'? 'Match the previous subexpression zero or once.
'+' Matches the previous subexpression once or multiple times.
'*' Matches the previous subexpression zero or multiple times.
'|' Indicates an option between the two items. Example '^ ([a-z] + | [0-9] +) $' indicates the combination of all lowercase letters or numbers
String.
'()' Indicates the start and end positions of a subexpression.
'[]' Indicates a bracket expression.
'{M, n}' indicates the exact number of occurrences. m = <number of occurrences <= n, '{m}' indicates m occurrences, '{m ,} 'indicates at least
Appears m times.
/Num matches num, where num is a positive integer. References to the obtained matching.
Character cluster:
[[: Alpha:] any letter.
[[: Digit:] any number.
[[: Alnum:] Any letter or number.
[[: Space:] any white characters.
[[: Upper:] Any uppercase letter.
[[: Lower:] Any lowercase letter.
[[: Punct:] Any punctuation marks.
[[: Xdigit:] Any hexadecimal number, which is equivalent to [0-9a-fA-F].
Operation priority of various operators
/Escape Character
(),(? :),(? =), [] Parentheses and square brackets
*, + ,?, {N}, {n ,}, {n, m} qualifier
^, $, Anymetacharacter location and Sequence

*/
-- Create a table
Create table fzq
(
Id varchar (4 ),
Value varchar (10)
);
-- Data insertion
Insert into fzq values
('1', '123 ');
Insert into fzq values
('2', '123 ');
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', '2014, 123 45 ');
Insert into fzq values
('8', 'adc de ');
Insert into fzq values
('9', 'adc,. de ');
Insert into fzq values
('10', '1b ');
Insert into fzq values
('10', 'abcbvbnb ');
Insert into fzq values
('11', '123 ');
Insert into fzq values
('11', '123 ');
-- Regexp_like
-- Query records whose names start with 1 and end with 60 and whose length is 7 characters
Select * from fzq where value like '1 ____ 60 ';
Select * from fzq where regexp_like (value, '1... 60 ');
-- Query records whose names start with 60 and end with 1 and whose length is 7 digits and all are numbers.
-- Using like is not a good implementation.
Select * from fzq where regexp_like (value, '1 [0-9] {4} 60 ');
-- The character set can also be used.
Select * from fzq where regexp_like (value, '1 [[: digit:] {4} 60 ');
-- Query records whose values are not pure numbers
Select * from fzq where not regexp_like (value, '^ [[: digit:] + $ ');
-- Query records whose values do not contain any numbers.
Select * from fzq where regexp_like (value, '^ [^ [: digit:] + $ ');
-- Query records starting with 12 or 1b. The records are case insensitive.
Select * from fzq where regexp_like (value, '^ 1 [2b]', 'I ');
-- Query records starting 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 containing punctuation marks.
Select * from fzq where regexp_like (value, '[[: punct:]');
/*
You can understand its syntax. The usage of other functions is similar.
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.