ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Aug 2012 11:58:18 +0200preparser state for regexshttps://ask.sagemath.org/question/9277/preparser-state-for-regexs/I would have expected the following to work:
reset()
import re
preparser(False) # preparser off else we have \\ instead of \
rx=re.compile(r".*(\sHun\s).*") # in the regex
m = rx.match(r"The Attila the Hun Show") # Find "Hun" in "The Attila the Hun Show"
if m: print "found =>", m.group(1) # 1 needs to be 1 not '1' here!
preparser(True)
In fact I get 'IndexError: no such group'. Using int(1) fixes the problem, but why? The preparser is off!
Even more curious the block works, as is, on every other evaluate! I tried moving the preparser(False) statement to before the import, but that makes no difference.oldbradThu, 30 Aug 2012 11:58:18 +0200https://ask.sagemath.org/question/9277/