Revision: 4245 Author: wikipedian Date: 2007-09-11 23:20:13 +0000 (Tue, 11 Sep 2007)
Log Message: ----------- bugfix: improved template regex in replaceExcept()
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2007-09-11 20:18:54 UTC (rev 4244) +++ trunk/pywikipedia/wikipedia.py 2007-09-11 23:20:13 UTC (rev 4245) @@ -2587,9 +2587,10 @@ # improve wiki source code readability. # 'template': re.compile(r'(?s){{.*?}}'), # The regex above fails on nested templates. This regex can handle - # templates inside templates, but no deeper cascades. - 'template': re.compile(r'(?s){{(({{.*?}})?.*?)*}}'), - + # templates cascaded up to level 3, but no deeper. For arbitrary + # depth, we'd need recursion which can't be done in Python's re. + # After all, the language of correct parenthesis words is not regular. + 'template': re.compile(r'(?s){{(({{(({{.*?}})|.)*}})|.)*}}'), }
# if we got a string, compile it as a regular expression