Using re wildcards in python script

Posted by Gregori on Wed 01 Nov 2006 05:18 PM — 3 posts, 20,345 views.

#0
import re

def ExampleTrigger (label, ontext, wildcards):
#world.note ("Trigger " + label + " fired.");
#world.note ("Matching line was: " + ontext);
if re.search('You are not on the ground!', ontext):
world.note ("Text matched!");

What I am trying to do I could handle in a normal regular expression trigger using (*.?) in this line.

You are not on the ground!

to make it look like this:

You are not (.*?) the (.*?)!

So it would match:

You are not on the ground!
You are not in the air!
You are not in the trees!

So the question is how do I concactanate the regex string in the script to do the same thing?

I tried:

if re.search('You are not ' + (.*?) + ' the ' + (.*?), ontext):

but it fails
Russia #1
Why do you want to concatenate them? There are no variable parts in that expression, so why not just use a simple literal string:

'You are not (.*?) the (.*?)'


But if you still want to concatenate the parts then you'll need to quote the captures:

'You are not ' + '(.*?)' + ' the ' + '(.*?)'
#2
Oh my god I am stupid. Thank you for pointing out the obvious to me I will go bang my head against a wall and cry now.