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.
|
Character |
Meaning |
|
|
An initial |
|
|
Specifies a range, for example |
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