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 ➜ Regular Expression Trigger

Regular Expression Trigger

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


Posted by Artel   USA  (65 posts)  Bio
Date Sat 25 Mar 2006 11:53 PM (UTC)

Amended on Sat 25 Mar 2006 11:54 PM (UTC) by Artel

Message
I've tried to make a trigger to try to capture only names from output such as:
     - (C) Zombie
     - (I)(T)(G)(W) a young thief
     - (R)(W) Fnor
     - Tom

However, the problem is that there may be any number of (C), (I), (G), such things before the names. I've managed to capture the names such as Zombie, a young thief, and Fnor; however, I cannot find a way to capture the name Tom.

The following regexp trigger will capture Zombie, a young thief, and Fnor:
^     \- \((.+)\) (.*?)$

Now I thought I could modify it like this to capture Tom:
^     \- (|\((.+)\) )(.*?)$

It does capture Tom, but now it also captures the parentheses all in the same wildcard.

Would anyone know how I could make a trigger to only capture the names from that list?

Artel.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 26 Mar 2006 04:38 AM (UTC)

Amended on Sun 26 Mar 2006 04:41 AM (UTC) by Nick Gammon

Message
It would help to put in a sequence for the name that is what you are expecting rather than the "." symbol because that matches everything, including brackets. This one worked for me in all cases:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^     \- (\([A-Z()]+\) )?([\w\s]+)"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>


This sequence here matches what is inside the brackets:


(\([A-Z()]+\) )?


It looks for the opening bracket, and then A-Z or other brackets, and then the closing bracket - and the space after it. The final ? means "0 or 1 of them" which allows for the case of Tom who has no brackets at all.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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,163 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.