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 ➜ Multi Line Triggers, Regex hell.

Multi Line Triggers, Regex hell.

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


Posted by Shigs   (27 posts)  Bio
Date Wed 06 Aug 2008 12:34 AM (UTC)
Message
I have multi-line strings.


Quote:
Tarmeh tells you his name. You feel some enlightenment and gain 1700
experience from the encounter.


Quote:

Tarmeh tells you his name and a lot about himself. You feel enlightened
by the information and gain 3850 experience from the encounter.
Quote:


How in my trigger do I account for, Tarmeh, isn't a constant, and how do I aqquire the number of experince points into a variable?
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #1 on Wed 06 Aug 2008 12:58 AM (UTC)
Message
That depends. Is the mud manually inserting newlines after a word, depending on the line length? (E.g. is the newline always after the same word or not?).

If it is always after the same word, just use \n to match the newline at the right spot. If it varies, you'll want to use \n? at every possible spot where the mud could insert a newline.

If your mud supports a soft-wrapping modus (letting your client do the wrapping) rather than wrapping lines itself, it would be easiest to turn that on and totally forget about matching on newlines.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Wed 06 Aug 2008 01:10 AM (UTC)

Amended on Wed 06 Aug 2008 01:11 AM (UTC) by Nick Gammon

Message
This might do it. Your basic problem is that the line break might appear after every word, so I changed a space to \s+ which is "one or more whitespace". A newline counts as whitespace, so this allows for newlines after the words.

I also made the variable parts ("some enlightenment" etc.) to just .* which would match anything.


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="(?s)^(\w+)\s+tells\s+you\s+his\s+name.*\.\s+You\s+feel\s+.+\s+and\s+gain\s+(\d+)\s+experience\s+from\s+the\s+encounter\.\Z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Matched on: %0
%%1 = %1
%%2 = %2</send>
  </trigger>
</triggers>



Running this on your test data gave this (output from trigger in bold):


Tarmeh tells you his name. You feel some enlightenment and gain 1700
experience from the encounter.
Matched on: Tarmeh tells you his name. You feel some enlightenment and gain 1700
experience from the encounter.
%1 = Tarmeh
%2 = 1700

Tarmeh tells you his name and a lot about himself. You feel enlightened
by the information and gain 3850 experience from the encounter.
Matched on: Tarmeh tells you his name and a lot about himself. You feel enlightened
by the information and gain 3850 experience from the encounter.
%1 = Tarmeh
%2 = 3850

- Nick Gammon

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

Posted by Shigs   (27 posts)  Bio
Date Reply #3 on Wed 06 Aug 2008 09:05 PM (UTC)
Message
Yet again Nick, You are a Legend.
Top

Posted by Shigs   (27 posts)  Bio
Date Reply #4 on Tue 12 Aug 2008 12:22 AM (UTC)
Message
How would,. I check for HIS or HER?


I've tried his|her and (his|her) and gotten nothing but errors, the trigger seems to fire, but the second parameter, returns a null value,
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Tue 12 Aug 2008 02:28 AM (UTC)
Message
If you add a new capture group by using parentheses, then you will have to change the %2 to be a %3 to reflect the fact that it is now the third capture group.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #6 on Tue 12 Aug 2008 11:25 AM (UTC)
Message
You can make the group a non-capture group by using (?:his|her) instead of just (his|her). That will prevent it from changing your %1 value.
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.


21,812 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.