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

Posted by Trevize on Thu 07 Sep 2006 11:24 PM — 3 posts, 15,318 views.

#0
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.
Australia Forum Administrator #1
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

Amended on Thu 07 Sep 2006 11:41 PM by Nick Gammon
#2
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.