Skip to Content
Oracle Regular Expressions Pocket Reference
book

Oracle Regular Expressions Pocket Reference

by Jonathan Gennick, Peter Linsley
September 2003
Intermediate to advanced
64 pages
1h 25m
English
O'Reilly Media, Inc.
Content preview from Oracle Regular Expressions Pocket Reference

Name

[ ] (Square Brackets) — Matches any of a set of characters

Synopsis

Use square brackets ([]) to create a matching list that will match on any one of the characters in the list.

The following example searches for a string of digits by applying the plus (+) quantifier to a matching list consisting of the set of digits 0-9:

SELECT REGEXP_SUBSTR(
   'Andrew is 14 years old.',
   '[0123456789]+ years old')
FROM dual;

14 years old

A better solution to this problem is to define a range of digits using the dash (-):

[0-9]+ years old

Even better is to specify a character class:

[[:digits:]]+ years old'

Begin a list with a caret (^) to create a non-matching list that specifies characters to which you do not want to match. The following extracts all of a sentence except the ending punctuation:

SELECT REGEXP_SUBSTR(
   'This is a sentence.',
   '.*[^.!:]')
FROM dual;

This is a sentence

Virtually all regular expression metacharacters lose their special meaning and are treated as regular characters when used within square brackets. The period in the previous SELECT statement provides an example of this, and Table 1-3 describes some exceptions to this general rule.

Table 1-3. Characters that retain special meaning within square brackets

Character

Meaning

^

An initial ^ defines a non-matching list. Otherwise, the ^ has no special meaning.

-

Specifies a range, for example 0-9. When used as the very first or very last character between brackets, or as the first character following a leading ^ within brackets, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Beginning Oracle SQL for Oracle Database 18c: From Novice to Professional

Beginning Oracle SQL for Oracle Database 18c: From Novice to Professional

Ben Brumm

Publisher Resources

ISBN: 0596006012Errata Page