Commit 9522085a authored by Tom Lane's avatar Tom Lane

Doc: work a little harder on the initial examples for regex matching.

Writing unnecessary '.*' at start and end of a POSIX regex doesn't
do much except confuse the reader about whether that might be
necessary after all.  Make the examples in table 9.16 a tad more
realistic, and try to turn the next group of examples into something
self-contained.

Per gripe from rmzgrimes.  Back-patch to v13 because it's easy.

Discussion: https://postgr.es/m/161215841824.14653.8969016349304314299@wrigleys.postgresql.org
parent f003a752
...@@ -5329,7 +5329,7 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea ...@@ -5329,7 +5329,7 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
String matches regular expression, case sensitively String matches regular expression, case sensitively
</para> </para>
<para> <para>
<literal>'thomas' ~ '.*thom.*'</literal> <literal>'thomas' ~ 't.*ma'</literal>
<returnvalue>t</returnvalue> <returnvalue>t</returnvalue>
</para></entry> </para></entry>
</row> </row>
...@@ -5343,7 +5343,7 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea ...@@ -5343,7 +5343,7 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
String matches regular expression, case insensitively String matches regular expression, case insensitively
</para> </para>
<para> <para>
<literal>'thomas' ~* '.*Thom.*'</literal> <literal>'thomas' ~* 'T.*ma'</literal>
<returnvalue>t</returnvalue> <returnvalue>t</returnvalue>
</para></entry> </para></entry>
</row> </row>
...@@ -5357,8 +5357,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea ...@@ -5357,8 +5357,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
String does not match regular expression, case sensitively String does not match regular expression, case sensitively
</para> </para>
<para> <para>
<literal>'thomas' !~ '.*thomas.*'</literal> <literal>'thomas' !~ 't.*max'</literal>
<returnvalue>f</returnvalue> <returnvalue>t</returnvalue>
</para></entry> </para></entry>
</row> </row>
...@@ -5371,8 +5371,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea ...@@ -5371,8 +5371,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
String does not match regular expression, case insensitively String does not match regular expression, case insensitively
</para> </para>
<para> <para>
<literal>'thomas' !~* '.*vadim.*'</literal> <literal>'thomas' !~* 'T.*ma'</literal>
<returnvalue>t</returnvalue> <returnvalue>f</returnvalue>
</para></entry> </para></entry>
</row> </row>
</tbody> </tbody>
...@@ -5406,10 +5406,12 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea ...@@ -5406,10 +5406,12 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
<para> <para>
Some examples: Some examples:
<programlisting> <programlisting>
'abc' ~ 'abc' <lineannotation>true</lineannotation> 'abcd' ~ 'bc' <lineannotation>true</lineannotation>
'abc' ~ '^a' <lineannotation>true</lineannotation> 'abcd' ~ 'a.c' <lineannotation>true &mdash; dot matches any character</lineannotation>
'abc' ~ '(b|d)' <lineannotation>true</lineannotation> 'abcd' ~ 'a.*d' <lineannotation>true &mdash; <literal>*</literal> repeats the preceding pattern item</lineannotation>
'abc' ~ '^(b|c)' <lineannotation>false</lineannotation> 'abcd' ~ '(b|x)' <lineannotation>true &mdash; <literal>|</literal> means OR, parentheses group</lineannotation>
'abcd' ~ '^a' <lineannotation>true &mdash; <literal>^</literal> anchors to start of string</lineannotation>
'abcd' ~ '^(b|c)' <lineannotation>false &mdash; would match except for anchoring</lineannotation>
</programlisting> </programlisting>
</para> </para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment