Snippet Name: Regular Expressions: RegExp examples three
Description: Patterns for matching Social Security Numbers, US phone numbers, US ZIP codes, and IP addresses.
Also see: » Regular Expressions: REGEXP_SUBSTR
» Regular Expressions: REGEXP_LIKE
» Regular Expressions: REGEXP_REPLACE
» Regular Expressions: RegExp examples t...
» Regular Expressions: RegExp examples o...
» Regular Expressions: Regexp Cheat Sheet
» RegExp: Append first name first letter...
Comment: (none)
Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 12th, 2009
|
-- search for Social Security Numbers (xxx-xx-xxxx)
SELECT *
FROM sandbox
WHERE REGEXP_LIKE(regex_test,'^[0-9]{3}-[0-9]{2}-[0-9]{4}$');
-- match US phone number with or without parentheses
SELECT *
FROM sandbox
WHERE REGEXP_LIKE(regex_test,'^\([0-9]{3}\)[:space:]?[0-9]{3}(-|[:space:])?[0-9]{4}$|^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$');
-- match US ZIP codes
SELECT *
FROM sandbox
WHERE REGEXP_LIKE(regex_test,'[0-9]{5}(?-[0-9]{4})?');
-- handy pattern for matching an IP address:
'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
|