Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Regular Expressions - RegExp examples #1 Jump to:  
Category: >> Oracle PL/SQL >> Regular Expressions - RegExp examples #1 Bookmark and Share

<< lastnext >>

Snippet Name: Regular Expressions - RegExp examples #1

Description: Examples of the various Oracle-supported regular expressions.

Also see:
» Regular Expressions - REGEXP_SUBSTR
» Regular Expressions - REGEXP_LIKE
» Regular Expressions - REGEXP_REPLACE
» Regular Expressions - RegExp examples ...
» Regular Expressions - RegExp examples ...
» Regular Expressions - Regexp Cheat She...
» RegExp - Append first name first lette...

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 12th, 2009

-- REGEXP_COUNT syntax:
REGEXP_COUNT(<source_string>, <pattern>
[[, <start_position>], [<match_parameter>]])
 
/*
-- match parameters:
'c' = case sensitive search/match
'i' = case insensitive search/match
'm' = parses the source string as individual lines
's' = parses the source string as a single line
'n' = allows a period (.) wild character to match a newline
'x' = instructs parser to ignore whitespace characters
*/
 
-- count occurrences based on a regular expression: 
SELECT REGEXP_COUNT(regex_col, '2a', 1, 'i') RESULT
FROM regex_test;
 
SELECT REGEXP_COUNT(regex_col, 'e', 1, 'i') RESULT
FROM regex_test;
 
-- REGEXP_INSTR syntax      
REGEXP_INSTR(<source_string>, <pattern>
[[, <start_position>]
[, <occurrence>]
[, <return_option>]
[, <match_parameter>]
[, <sub_expression>]])
 
-- Find words beginning with 's' or 'r' or 'p' followed 
-- by any 4 alphabetic characters (case insensitive) 
SELECT REGEXP_INSTR('The slippery rabbit was pursued by a ravenous wolf', '[o][[:alpha:]]{3}', 1, 1, 0, 'i') RESULT
FROM dual;
 
 
- find the position OF 'calls', 'calling', 'called' OR 'caller'      
SELECT REGEXP_INSTR('You have called me far too many times, she said.', 'call((ing)|(ed)|(s)|(er))') 
RESULTNUM
FROM dual;
 
 
Using sub-expression OPTION      
SELECT regex_col, REGEXP_INSTR(regex_col, 'ab', 1, 1, 0, 'i', 0)
FROM regex_test;
 
 
-- REGEXP_LIKE syntax:      
REGEXP_LIKE(<source_string>, <pattern>, <match_parameter>)
 
 
-- match only alphanumeric characters (a-z, A-Z, and 0-9)
SELECT *
FROM regex_test
WHERE REGEXP_LIKE(regex_col, '[[:alnum:]]');
 
 
-- match only 3 alphanumeric characters (a-z, A-Z, and 0-9)
SELECT *
FROM regex_test
WHERE REGEXP_LIKE(regex_col, '[[:alnum:]]{3}');
 
 
-- match only alphabetic characters (a-z and A-Z)
SELECT *
FROM test
WHERE REGEXP_LIKE(testcol, '[[:alpha:]]');
 
SELECT *
FROM test
WHERE REGEXP_LIKE(testcol, '[[:alpha:]]{3}');
 
 
 
 
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 152 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?