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 ➜ General ➜ Need help with text handling (from wildcard in trigger)

Need help with text handling (from wildcard in trigger)

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


Posted by Lerkista   (57 posts)  Bio
Date Tue 09 Aug 2016 04:34 AM (UTC)
Message
Hi

I want to make a trigger and do some actions depending the text, for example


Match: You see * in this room


But %1 can be any of this (for example):


a rat
an elephant
Sargent Lewis
Maria


how can i get that %1 be:


cat
elephant
Sargent Lewis


i mean, in the first two cases, eliminate the "a " and "an ", and let "Sargent Lewis" as is

otr other way is with two triggers:

One trigger that match:


"^You see (a|an) (.*?) in this room$


and works with the first 2 cases, but don't know what to do to match the last two

Something like get the name if not start with A and An

Any help??

Thanks
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 09 Aug 2016 04:59 AM (UTC)
Message
How about this?


^You see (?:(?:a|an) )?(.*?) in this room$


The "?:" stops it being captured (so the name is still %1).

What this is looking for is "a" or "an" followed by a space, which itself is optional, preceding the word.

An alternative would be to have the space after each optional word, like this:


^You see (?:a |an )?(.*?) in this room$


And if you omit the "?:" then the matching word (eg. Maria) becomes wildcard #2. eg.


^You see (a |an )?(.*?) in this room$

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lerkista   (57 posts)  Bio
Date Reply #2 on Tue 09 Aug 2016 05:16 AM (UTC)
Message
Hi

That works perfect

thanks
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.


11,053 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.