[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  Using re wildcards in python script
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Using re wildcards in python script

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


Posted by Gregori   (2 posts)  [Biography] 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
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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 ' + '(.*?)'
[Go to top] top

Posted by Gregori   (2 posts)  [Biography] 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.
[Go to top] 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.


6,731 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]