Top Previous Next TOC Index

OWA_PATTERN Package


The OWA_PATTERN package enables you to do sophisticated string manipulation using regular expressions. OWA_PATTERN provides the following three operations:

There are also operations that these operations use, but that you can also use directly. These are explained shortly.

The OWA_PATTERN operations all use the following three parameters:

Some of the operations take additional parameters as well.


Regular Expressions

You specify a regular expression by creating the string you want to match interspersed with various wildcard tokens and quantifiers. The wildcard tokens all match something other than themselves, and the quantifiers modify the meaning of tokens or of literals by specifying such things as how often each is to be applied.


Tokens

The wildcard tokens that are supported are as follows:

^ Matches newline or the beginning of the target.

$ Matches newline or the end of the target.

\n Matches newline.

. Matches any character except newline.

\t Matches tab.

\d Matches digits [0-9]

\D Matches non-digits [not 0-9]

\w Matches word characters (alphanumeric) [0-9, a-z, A-Z or _]

\W Matches non-word characters [not 0-9, a-z, A-Z or _]

\s Matches whitespace characters [blank, tab, or newline]

\S Matches non-whitespace characters [not blank, tab, or newline]

\b Matches "word" boundaries (between \w and \W)

\x<HEX> Matches the value in the current character set of the two hexidecimal digits.

\<OCT> Matches the value in the current character set of the two or three octal digits.

\ Followed by any character not covered by another case matches that character.

& Applies only to CHANGE. This causes the string that matched the regular expression to be included in the string that replaces it. This differs from the other tokens in that it specifies how a target is changed rather than how it is matched. This is explained further under CHANGE.


Quantifiers

Any of the above tokens except & can have its meaning extended by any of the following quantifiers. You can also apply these quantifiers to literals.

? 0 or 1 occurrence(s)

* 0 or more occurrences

+ 1 or more occurrence(s)

{n} Exactly n occurrences

(n,} At least n occurrences

{n,m} At least n, but not more than m, occurrences


Flags

In addition to targets and regular expressions, the OWA_PATTERN functions and procedures can use flags to affect how they are interpreted. The recognized flags are as follows:

i This indicates a case-insensitive search.

g This applies only to CHANGE. It indicates a global replace. That is to say, all portions of the target that match the regular expression are replaced.


Datatypes

The following special datatype is used by OWA_PATTERN.

pattern
A PL/SQL table (see PL/SQL Tables) of 4 byte VARCHAR2 strings, indexed by BINARY INTEGER. This is an alternative way to store your regular expression than in simple VARCHAR2 strings. The advantages of this is that you can use a pattern as both an input and output parameter. Thus, you can pass the same regular expression to several subsequent OWA_PATTERN function calls, and it only has to be parsed once.

Note: The following datatypes are used by OWA_PATTERN, but are part of the OWA_TEXT package. For information on these, see the section on OWA_TEXT: owa_text.vc_array, owa_text.multi_line, owa_text.int_array, owa_text.row_list.


Using MATCH, AMATCH, and CHANGE

Here is an example of MATCH.

MATCH ('BATMAN', 'Bat.*', i);

This is how the function is interpreted: BATMAN is the target where we are searching for the regular expression. Bat.* is the regular expression we are attempting to find. The period (.) indicates any character other than newline, and the asterisk (*) indicates any 0 or more of such. Therefore, this regular expression specifies that a matching target consists of 'Bat', followed by any set of characters neither ending in nor including a newline (which does not match the period). The i at the end is a flag indicating that case is to be ignored in the search.

This would return TRUE, indicating that a match had been found.

Note that, if multiple overlapping strings can match the regular expression, OWA_PATTERN takes the longest match.


Summaries of OWA_PATTERN Functions

MATCH, AMATCH, and CHANGE are overloaded. That is to say, there are several versions of each, distinguished by the parameters they take. Specifically, there are six versions of MATCH, and four each of AMATCH and CHANGE. This section provides a summary of all versions; the following section provides a reference on each version.

MATCH is a function that returns TRUE or FALSE depending on whether a match was found. Here is a summary of the versions of MATCH:

AMATCH is a function giving a number that indicates the number of characters from the beginning of the target to the end of the first match found (AMATCH stops searching after the first match). If no match is found, it returns 0. Here is a summary of the versions of AMATCH:

CHANGE can be either a procedure or a function, depending on how it is invoked. If a function, it returns the number of changes made. If the flag 'g' is not used, this number can be only 0 or 1. Here is a summary of the versions of CHANGE

Here are the formal descriptions of the OWA_PATTERN procedures and functions.


Procedures and Functions


owa_pattern.match (version 1)

Syntax
owa_pattern.match(line, pat, flags)

Purpose
Enables programmers to search a string for a pattern using regular expressions.

Parameters
line in varchar2
pat in varchar2
flags in varchar2 DEFAULT NULL

Generates
Boolean indicating whether match was found.


owa_pattern.match (version 2)

Syntax
owa_pattern.match(line, pat, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
line in varchar2
pat in out pattern
flags in varchar2 DEFAULT NULL

Generates
Boolean indicating whether match was found.


owa_pattern.match (version 3)

Syntax
owa_pattern.match(line, pat, backrefs, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
line in varchar2
pat in varchar2
backrefs out owa_text.vc_arr
flags in varchar2 DEFAULT NULL

Generates
Boolean indicating whether match was found.


owa_pattern.match (version 4)

Syntax
owa_pattern.match(line, pat, backrefs, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
line in varchar2
pat in out pattern
backrefs out owa_text.vc_arr
flags in varchar2 DEFAULT NULL

Generates
Boolean indicating whether match was found.


owa_pattern.match (version 5)

Syntax
owa_pattern.match(mline, pat, rlist, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
mline in owa_text.multi_line
pat in varchar2
rlist out owa_text.row_list
flags in varchar2 DEFAULT NULL

Generates
Boolean indicating whether match was found.


owa_pattern.match (version 6)

Syntax
owa_pattern.match(mline, pat, rlist, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
mline in owa_text.multi_line
pat in out pattern
rlist out owa_text.row_list
flags in varchar2 DEFAULT NULL

Generates
Boolean indicating whether match was found.


owa_pattern.amatch (version 1)

Syntax
owa_pattern.match(line, from_loc, pat, flags)

Purpose
Enables programmers to search a string for a pattern using regular expressions.

Parameters
line in varchar2
from_loc ini nteger
pat in varchar2
flags in varchar2 DEFAULT NULL

Generates
Location (in number of characters from the beginning) of the end of the match. 0 if none such.


owa_pattern.amatch (version 2)

Syntax
owa_pattern.match(line, from_loc, pat, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
line in varchar2
from_loc in integer
pat in out pattern
flags in varchar2 DEFAULT NULL

Generates
Location (in number of characters from the beginning) of the end of the match. 0 if none such.


owa_pattern.amatch (version 3)

Syntax
owa_pattern.match(line, from_loc, pat, backrefs, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
line in varchar2
from_loc in integer
pat in varchar2
backrefs out owa_text.vc_arr
flags in varchar2 DEFAULT NULL

Generates
Location (in number of characters from the beginning) of the end of the match. 0 if none such.


owa_pattern.amatch (version 4)

Syntax
owa_pattern.match(line, from_loc, pat, backrefs, flags)

Purpose
Enables programmers to search a string for a pattern using regular expression

Parameters
line in varchar2
from_loc in integer
pat in out pattern
backrefs out owa_text.vc_arr
flags in varchar2 DEFAULT NULL

Generates
Location (in number of characters from the beginning) of the end of the match. 0 if none such.


owa_pattern.change (version 1)

Syntax
owa_pattern.match(line, from_str, to_str, flags)

Purpose
This version is a function. It enables programmers to search a string for a pattern and replace it.

Parameters
line in out varchar2
from_str in varchar2
to_str in varchar2
flags in varchar2 DEFAULT NULL

Generates
Revises line parameter. Function outputs number of substitutions made.


owa_pattern.change (version 2)

Syntax
owa_pattern.match(line, from_str, to_str, flags)

Purpose
This version is a procedure. It enables programmers to search a string for a pattern and replace it.

Parameters
line in out varchar2
from_str in varchar2
to_srt in varchar2
flags in varchar2 DEFAULT NULL

Generates
Revises line parameter.


owa_pattern.change (version 3)

Syntax
owa_pattern.match(mline, from_str, to_str, backrefs, flags)

Purpose
This version is a function. It enables programmers to search a multi_line for a pattern and replace it.

Parameters
mline in out multi_line
from_str in varchar2
to_srt in varchar2
flags in varchar2 DEFAULT NULL

Generates
Revises mline parameter. Function outputs number of substitutions made.


owa_pattern.change (version 4)

Syntax
owa_pattern.match(mline, from_str, to_str, flags)

Purpose
This version is a procedure. It enables programmers to search a multi_line for a pattern and replace it.

Parameters
mline in out multi_line
from_str in varchar2
to_srt in varchar2
flags in varchar2 DEFAULT NULL

Generates
Revises mline parameter.


owa_pattern.getpat

Syntax
owa_pattern.getpat(arg, pat)

Purpose
This converts a VARCHAR2 string into the special datatype pattern. This datatypes is explained under OWA_PATTERN Datatypes.

Parameters
arg in varchar2
pat in out pattern

Generates
pattern.


Click Here to Go to the top of the section.

Click Here to Go to the previous topic.

Click Here to Go to the next topic.

Click here to Go to the Table of Contents.

Click here to Go to the Index.


This document was last modified at 05:39pm PST on March 27, 1996.

To report any problems or comments, e-mail Oracle WebServer Documentation.