Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Python ➜ Using re wildcards in python script

Using re wildcards in python script

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Gregori   (2 posts)  Bio
Date Wed 01 Nov 2006 05:18 PM (UTC)
Message
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
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #1 on Wed 01 Nov 2006 06:18 PM (UTC)
Message
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 ' + '(.*?)'
Top

Posted by Gregori   (2 posts)  Bio
Date Reply #2 on Wed 01 Nov 2006 06:27 PM (UTC)
Message
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.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,637 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.