Doc: work a little harder on the initial examples for regex matching.
authorTom Lane
Mon, 1 Feb 2021 21:38:52 +0000 (16:38 -0500)
committerTom Lane
Mon, 1 Feb 2021 21:38:52 +0000 (16:38 -0500)
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

doc/src/sgml/func.sgml

index f30eaa3e4bac65ba7f1bca4605db4dd1c0b8f21e..081f04ce1a9fb200dd5458d94f38a68019e98f4c 100644 (file)
@@ -5329,7 +5329,7 @@ substring('foobar' similar '#"o_b#"%' escape '#')    NULL
         String matches regular expression, case sensitively
        
        
-        'thomas' ~ '.*thom.*'
+        'thomas' ~ 't.*ma'
         t
        
        
@@ -5343,7 +5343,7 @@ substring('foobar' similar '#"o_b#"%' escape '#')    NULL
         String matches regular expression, case insensitively
        
        
-        'thomas' ~* '.*Thom.*'
+        'thomas' ~* 'T.*ma'
         t
        
        
@@ -5357,8 +5357,8 @@ substring('foobar' similar '#"o_b#"%' escape '#')    NULL
         String does not match regular expression, case sensitively
        
        
-        'thomas' !~ '.*thomas.*'
-        f
+        'thomas' !~ 't.*max'
+        t
        
        
 
@@ -5371,8 +5371,8 @@ substring('foobar' similar '#"o_b#"%' escape '#')    NULL
         String does not match regular expression, case insensitively
        
        
-        'thomas' !~* '.*vadim.*'
-        t
+        'thomas' !~* 'T.*ma'
+        f
        
        
       
@@ -5406,10 +5406,12 @@ substring('foobar' similar '#"o_b#"%' escape '#')    NULL
     
      Some examples:
 
-'abc' ~ 'abc'    true
-'abc' ~ '^a'     true
-'abc' ~ '(b|d)'  true
-'abc' ~ '^(b|c)' false
+'abcd' ~ 'bc'     true
+'abcd' ~ 'a.c'    true — dot matches any character
+'abcd' ~ 'a.*d'   true — * repeats the preceding pattern item
+'abcd' ~ '(b|x)'  true — | means OR, parentheses group
+'abcd' ~ '^a'     true — ^ anchors to start of string
+'abcd' ~ '^(b|c)' false — would match except for anchoring