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 ➜ Pattern, not matching a word and evrything else.. (Multi line)

Pattern, not matching a word and evrything else.. (Multi line)

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


Posted by Trevize   (21 posts)  Bio
Date Thu 07 Sep 2006 11:24 PM (UTC)
Message
Can anyone help me, im going nuts on this.. Im trying to take out the name and title from the person in this string.

Example 1:
Your telepathic efforts are successful, and the mind of Terri Lothain is locked
with your own.

Example 2:
Your telepathic efforts are successful, and the mind of Mist of the Shadows,
Zith Q'azis, Vanishing Light is locked with your own.

Example 3:
Your telepathic efforts are successful, and the mind of Mist of Shadows, Zith
Q'azis, Vanishing Light is locked with your own.

Technicly I want to get evrything between "mind of " to " is locked". The problem im having is when there's a new line inbetween and I dont know where. I've tried: ^Your telepathic efforts are successful\, and the mind of (?s)(.*) is locked with your own\.$ but not only does %1 it give this: "[string "Trigger: "]:1: unfinished string near `"wtf Mist of the Shadows,'". It does'nt work for example 1...

I would be very grateful for any help I could get. Thank you.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 07 Sep 2006 11:37 PM (UTC)

Amended on Thu 07 Sep 2006 11:41 PM (UTC) by Nick Gammon

Message
You have two problems here, both can be fixed. :)


  1. Not matching when the fixed text spans a line. You can fix that by putting \s instead of a space in the match text. The sequence \s matches whitespace, and thus a newline counts as whitespace. Maybe make it \s+ to match one or more whitespace, but I didn't seem to need to do that.

  2. If the wildcard spans a line the variable %1 becomes a multi-line string. In Lua you can have multi-line strings, so I just did this:

    name = [[%1]]

    That handles single or multi-line string.


My trigger, which worked on all your examples, was:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="3"
   match="^Your\stelepathic\sefforts\sare\ssuccessful\,\sand\sthe\smind\sof\s(?s)(.*)\sis\slocked\swith\syour\sown\.$"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>name = [[%1]]
name = string.gsub (name, "\\n", " ")
print ("name=" .. name)</send>
  </trigger>
</triggers>



I used Lua here, and a string.gsub to remove the linefeed if it was inside the name string.

If you don't want to script in Lua, you can call a script subroutine (rather than scripting inline) in which case the wildcard is just a variable, and can be assigned in the normal way, whether or not it has multiple lines in it. eg. in VBscript:


Sub MyTrigger (name, line, wildcards)

  Note "matched on " & wildcards (1)

End Sub


- Nick Gammon

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

Posted by Trevize   (21 posts)  Bio
Date Reply #2 on Sat 09 Sep 2006 08:36 AM (UTC)

Amended on Sat 09 Sep 2006 08:38 AM (UTC) by Trevize

Message
Thanks alot with a very few adjustments it worked perfect! I did't know that \s could match an newline aswell. I just added the {1,2} behind the \s after the capture of the name and title. In case it had an empty space behind and then a linebreak.

^Your telepathic efforts are successful\, and the mind of (?s)(.*)\s{1,2}is\s{1,2}locked\s{1,2}with\s{1,2}your\s{1,2}own\.$

Thank you.
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.


12,249 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.