reg exp help

JRCondon jcondon at
Tue Jul 27 22:33:29 CEST 2004

No need for regex here; you can do this with strings:

>>> text = '5EHello'
>>> def lengthCheckedString(text):
        from string import split
	stext = split(text,'E',1)
	if int(stext[0]) == len(stext[1]):
		return stext[1]
		return None
>>> lengthCheckedString(text)

But, if you want to use a regex:
>>> def lengthCheckedStringRE(text):
        import re
	m = re.match('(?P<txtlen>\d+)E(?P<txt>.*$)',text)
	txt ='txt')
	if int('txtlen')) == len(txt):
		return txt
		return None

>>> lengthCheckedStringRE(text)


More information about the Python-list mailing list