Woah.. I want that for Python..
I sure don’t. Putting a regular expression in a slice for a string runs totally counter to all existing python idioms, and would utterly confuse anyone trying to read the code. There are definitely other ways of accomplishing this with reasonably compact syntax that are also intuitive and clear. (But I'm unconvinced it needs special syntax at all. It saves a couple lines here and there, maybe, but at the cost of maki…
>>> re.search('a(x)a', 'axa').group(1)
'x'
>>> re.search('a(x)a', 'aya').group(1)
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'NoneType' object has no attribute 'group'
The idiomatic python for the job is: match = re.search("`([^']*)'", caller[0])
if match:
match.group(1)
else:
None
(or some nonsense involving try/except, which would be even worse).