Commits

Jonathan Eunice committed 6a22f57

tweaks

Comments (0)

Files changed (3)

     if some_string in Re(pattern):
         print Re._[1]
         
-This turns the sense of the matching around, asking "is the given string *in*
+``pattern`` here would typically be a string, but it can also be a pre-existing
+compiled regular expression. ``Re`` objects are `memoized
+<http://en.wikipedia.org/wiki/Memoization>`_ for efficiency, so they so they're
+only compiled once, regardless of how many times they're mentioned in the
+program.
+        
+Note that the ``in`` test turns the sense of the matching around (compared to
+the standard ``re`` module). It asks "is the given string *in*
 the set of items this pattern describes?" To be fancy, the
 ``Re`` pattern is an intensionally
 defined set (namely "all strings matching the pattern"). This order often makes
     
 Pretty much all of the methods and properties one can access from the standard
 ``re`` module are available.
-   
-``Re`` objects are `memoized <http://en.wikipedia.org/wiki/Memoization>`_ for efficiency, so they
-so they're only compiled once, regardless of how many times
-they're mentioned in the program.
 
 Bonus: Globs
 ============
         return f
     
     def regrouped_fn(match):
-        return f(ReMatch(match))
+        re_match = ReMatch(match)
+        return f(re_match)
     
     return regrouped_fn
 
     
     assert 'ddd' not in sword
     assert 'it goes other ways' not in sword
-    assert 'it goes other ways sometimes' in sword
-    
+    assert 'it goes other ways sometimes' in sword    
     
 def test_findall():
     tests = 'some string with things in it ok?'
     newsent = re_pat.sub(repl, sentence)
     assert newsent == "you've been a BAD boy"
     
+    sentcap = Re(r'^(?P<first>.)')
+    sentcap_repl = lambda m: m.first.upper()
+    
+    assert sentcap.sub(sentcap_repl, newsent) == "You've been a BAD boy"
+    
     
 def test_memoization():    
     testpat  = Re(r'\b(s\w*)\b')