REGEXP_SUBSTR (2024)

REGEXP_SUBSTR extends the functionality of the SUBSTR function by letting you search a string for a regular expression pattern. It is also similar to REGEXP_INSTR, but instead of returning the position of the substring, it returns the substring itself. This function is useful if you need the contents of a match string but not its position in the source string. The function returns the string as VARCHAR2 or CLOB data in the same character set as source_char.

This function complies with the POSIX regular expression standard and the Unicode Regular Expression Guidelines. For more information, refer to Oracle Regular Expression Support.

  • source_char is a character expression that serves as the search value. It is commonly a character column and can be of any of the data types CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.

  • pattern is the regular expression. It is usually a text literal and can be of any of the data types CHAR, VARCHAR2, NCHAR, or NVARCHAR2. It can contain up to 512 bytes. If the data type of pattern is different from the data type of source_char, then Oracle Database converts pattern to the data type of source_char. For a listing of the operators you can specify in pattern, refer to Oracle Regular Expression Support.

  • position is a positive integer indicating the character of source_char where Oracle should begin the search. The default is 1, meaning that Oracle begins the search at the first character of source_char.

  • occurrence is a positive integer indicating which occurrence of pattern in source_char Oracle should search for. The default is 1, meaning that Oracle searches for the first occurrence of pattern.

    If occurrence is greater than 1, then the database searches for the second occurrence beginning with the first character following the first occurrence of pattern, and so forth. This behavior is different from the SUBSTR function, which begins its search for the second occurrence at the second character of the first occurrence.

  • match_param is a character expression of the data type VARCHAR2 or CHAR that lets you change the default matching behavior of the function. The behavior of this parameter is the same for this function as for REGEXP_COUNT. Refer to REGEXP_COUNT for detailed information.

  • For a pattern with subexpressions, subexpr is a nonnegative integer from 0 to 9 indicating which subexpression in pattern is to be returned by the function. This parameter has the same semantics that it has for the REGEXP_INSTR function. Refer to REGEXP_INSTR for more information.

See Also:

The following example examines the string, looking for the first substring bounded by commas. Oracle Database searches for a comma followed by one or more occurrences of non-comma characters followed by a comma. Oracle returns the substring, including the leading and trailing commas.

SELECT REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA', ',[^,]+,') "REGEXPR_SUBSTR" FROM DUAL;REGEXPR_SUBSTR-----------------, Redwood Shores,

The following example examines the string, looking for http:// followed by a substring of one or more alphanumeric characters and optionally, a period (.). Oracle searches for a minimum of three and a maximum of four occurrences of this substring between http:// and either a slash (/) or the end of the string.

SELECT REGEXP_SUBSTR('http://www.example.com/products', 'http://([[:alnum:]]+\.?){3,4}/?') "REGEXP_SUBSTR" FROM DUAL;REGEXP_SUBSTR----------------------http://www.example.com/

The next two examples use the subexpr argument to return a specific subexpression of pattern. The first statement returns the first subexpression in pattern:

SELECT REGEXP_SUBSTR('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 1) "REGEXP_SUBSTR" FROM DUAL;REGEXP_SUBSTR-------------------123

The next statement returns the fourth subexpression in pattern:

SELECT REGEXP_SUBSTR('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 4) "REGEXP_SUBSTR" FROM DUAL;REGEXP_SUBSTR-------------------78

REGEXP_SUBSTR pattern matching: Examples

The following statements create a table regexp_temp and insert values into it:

CREATE TABLE regexp_temp(empName varchar2(20), emailID varchar2(20));INSERT INTO regexp_temp (empName, emailID) VALUES ('John Doe', '[email protected]');INSERT INTO regexp_temp (empName, emailID) VALUES ('Jane Doe', 'janedoe');

In the following example, the statement queries the email column and searches for valid email addresses:

SELECT empName, REGEXP_SUBSTR(emailID, '[[:alnum:]]+\@[[:alnum:]]+\.[[:alnum:]]+') "Valid Email" FROM regexp_temp;EMPNAME Valid Email-------- -------------------John Doe [email protected] Doe

In the following example, the statement queries the email column and returns the count of valid email addresses:

SELECT empName, REGEXP_SUBSTR(emailID, '[[:alnum:]]+\@[[:alnum:]]+\.[[:alnum:]]+') "Valid Email", REGEXP_INSTR(emailID, '\w+@\w+(\.\w+)+') "FIELD_WITH_VALID_EMAIL" FROM regexp_temp;EMPNAMEValid EmailFIELD_WITH_VALID_EMAIL-------------------------------------------------John [email protected] Doe 

In the following example, numbers and alphabets are extracted from a string:

with strings as ( select 'ABC123' str from dual union all select 'A1B2C3' str from dual union all select '123ABC' str from dual union all select '1A2B3C' str from dual ) select regexp_substr(str, '[0-9]') First_Occurrence_of_Number, regexp_substr(str, '[0-9].*') Num_Followed_by_String, regexp_substr(str, '[A-Z][0-9]') Letter_Followed_by_String from strings;FIRST_OCCURRENCE_OF_NUMB NUM_FOLLOWED_BY_STRING LETTER_FOLLOWED_BY_STRIN------------------------ ------------------------ ------------------------1 123 C11 1B2C3 A11 123ABC1 1A2B3C A2

In the following example, passenger names and flight information are extracted from a string:

with strings as ( select 'LHRJFK/010315/JOHNDOE' str from dual union all select 'CDGLAX/050515/JANEDOE' str from dual union all select 'LAXCDG/220515/JOHNDOE' str from dual union all select 'SFOJFK/010615/JANEDOE' str from dual ) SELECT regexp_substr(str, '[A-Z]{6}') String_of_6_characters, regexp_substr(str, '[0-9]+') First_Matching_Numbers, regexp_substr(str, '[A-Z].*$') Letter_by_other_characters, regexp_substr(str, '/[A-Z].*$') Slash_letter_and_characters FROM strings;STRING_OF_6_CHARACTERSFIRST_MATCHING_NUMBERSLETTER_BY_OTHER_CHARACTERSSLASH_LETTER_AND_CHARACTERS-------------------------------------------------------------------------------------------------LHRJFK 010315 LHRJFK/010315/JOHNDOE /JOHNDOECDGLAX 050515 CDGLAX/050515/JANEDOE /JANEDOELAXCDG 220515 LAXCDG/220515/JOHNDOE /JOHNDOESFOJFK 010615 SFOJFK/010615/JANEDOE /JANEDOE
REGEXP_SUBSTR (2024)
Top Articles
Golden Butterfly Portfolio Insights – Backtest And Performance - Quantified Strategies
How To Coach Hiring Managers Through the 5 Steps of the Hiring Process
Xre-02022
Friskies Tender And Crunchy Recall
Comcast Xfinity Outage in Kipton, Ohio
How To Get Free Credits On Smartjailmail
Delectable Birthday Dyes
Optum Medicare Support
Category: Star Wars: Galaxy of Heroes | EA Forums
Www Thechristhospital Billpay
How Many Cc's Is A 96 Cubic Inch Engine
Trini Sandwich Crossword Clue
180 Best Persuasive Essay Topics Ideas For Students in 2024
Letter F Logos - 178+ Best Letter F Logo Ideas. Free Letter F Logo Maker. | 99designs
Leader Times Obituaries Liberal Ks
Does Breckie Hill Have An Only Fans – Repeat Replay
Harem In Another World F95
Nail Salon Goodman Plaza
Voy Boards Miss America
List of all the Castle's Secret Stars - Super Mario 64 Guide - IGN
Fraction Button On Ti-84 Plus Ce
Lcwc 911 Live Incident List Live Status
Copart Atlanta South Ga
V-Pay: Sicherheit, Kosten und Alternativen - BankingGeek
Wisconsin Volleyball Team Boobs Uncensored
Construction Management Jumpstart 3Rd Edition Pdf Free Download
Foolproof Module 6 Test Answers
Koninklijk Theater Tuschinski
Used Patio Furniture - Craigslist
Telegram Voyeur
How do you get noble pursuit?
Sandals Travel Agent Login
Harrison 911 Cad Log
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Stouffville Tribune (Stouffville, ON), March 27, 1947, p. 1
Gus Floribama Shore Drugs
Pfcu Chestnut Street
Boneyard Barbers
Pnc Bank Routing Number Cincinnati
Gideon Nicole Riddley Read Online Free
Atlantic Broadband Email Login Pronto
Jennifer Reimold Ex Husband Scott Porter
Wattengel Funeral Home Meadow Drive
Smith And Wesson Nra Instructor Discount
Timberwolves Point Guard History
Firestone Batteries Prices
Senior Houses For Sale Near Me
Chubbs Canton Il
From Grindr to Scruff: The best dating apps for gay, bi, and queer men in 2024
Adams-Buggs Funeral Services Obituaries
Latest Posts
Article information

Author: Kimberely Baumbach CPA

Last Updated:

Views: 5798

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kimberely Baumbach CPA

Birthday: 1996-01-14

Address: 8381 Boyce Course, Imeldachester, ND 74681

Phone: +3571286597580

Job: Product Banking Analyst

Hobby: Cosplaying, Inline skating, Amateur radio, Baton twirling, Mountaineering, Flying, Archery

Introduction: My name is Kimberely Baumbach CPA, I am a gorgeous, bright, charming, encouraging, zealous, lively, good person who loves writing and wants to share my knowledge and understanding with you.