From 6a0f486a25a5a85fa973a99914fea8ae40a0b722 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 16 Dec 2000 19:33:23 +0000 Subject: [PATCH] A little wordsmithing in the pattern-matching section. --- doc/src/sgml/func.sgml | 91 +++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 48bdb2a5e1c..fdd1c34a3e1 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,4 +1,4 @@ - + Functions and Operators @@ -805,12 +805,12 @@ If pattern does not contain percent - signs or underscore then the pattern only represents the string + signs or underscore, then the pattern only represents the string itself; in that case LIKE acts like the equals operator. An underscore (_) in pattern stands for (matches) any single - character, a percent sign (%) matches zero or - more characters. + character; a percent sign (%) matches any string + of zero or more characters. @@ -827,33 +827,39 @@ LIKE pattern matches always cover the entire - string. On order to match a pattern anywhere within a string, the + string. To match a pattern anywhere within a string, the pattern must therefore start and end with a percent sign. - In order to match a literal underscore or percent sign, the - respective character in pattern must be - preceded by the active escape character. The default escape + To match a literal underscore or percent sign without matching + other characters, the respective character in + pattern must be + preceded by the escape character. The default escape character is the backslash but a different one may be selected by - using the ESCAPE clause. When using the - backslash as escape character in literal strings it must be - doubled, because the backslash already has a special meaning in - string literals. + using the ESCAPE clause. To match the escape + character itself, write two escape characters. + + + + Note that the backslash already has a special meaning in string + literals, so to write a pattern constant that contains a backslash + you must write two backslashes in the query. You can avoid this by + selecting a different escape character with ESCAPE. The keyword ILIKE can be used instead of LIKE to make the match case insensitive according - to the active locale. This is a + to the active locale. This is not in the SQL standard but is a Postgres extension. The operator ~~ is equivalent to - LIKE, ~~* corresponds to - ILIKE. Finally, there are also - !~~ and !~~* operators to + LIKE, and ~~* corresponds to + ILIKE. There are also + !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE. All of these are also Postgres-specific. @@ -864,25 +870,6 @@ POSIX Regular Expressions - - POSIX regular expressions provide a more powerful means for - pattern matching than the LIKE function. - Many Unix tools such as egrep, - sed, or awk use a pattern - matching language that is similar to the one described here. - - - - A regular expression is a character sequence that is an - abbreviated definition of a set of strings (a regular - set). A string is said to match a regular expression - if it is a member of the regular set described by the regular - expression. Unlike the LIKE operator, a - regular expression also matches anywhere within a string, unless - the regular expression is explicitly anchored to the beginning or - end of the string. - - Regular Expression Match Operators @@ -920,6 +907,29 @@
+ + POSIX regular expressions provide a more powerful means for + pattern matching than the LIKE function. + Many Unix tools such as egrep, + sed, or awk use a pattern + matching language that is similar to the one described here. + + + + A regular expression is a character sequence that is an + abbreviated definition of a set of strings (a regular + set). A string is said to match a regular expression + if it is a member of the regular set described by the regular + expression. As with LIKE, pattern characters + match string characters exactly unless they are special characters + in the regular expression language --- but regular expressions use + different special characters than LIKE does. + Unlike LIKE patterns, a + regular expression is allowed to match anywhere within a string, unless + the regular expression is explicitly anchored to the beginning or + end of the string. + + @@ -927,8 +937,8 @@ 1003.2, come in two forms: modern REs (roughly those of egrep; 1003.2 calls these extended REs) and obsolete REs (roughly those of - ed; 1003.2 basic REs). Obsolete - REs are not available in Postgres. + ed; 1003.2 basic REs). + Postgres implements the modern form. @@ -1004,6 +1014,13 @@ \. + + Note that the backslash (\) already has a special + meaning in string + literals, so to write a pattern constant that contains a backslash + you must write two backslashes in the query. + + A bracket expression is a list of characters enclosed in []. It normally matches