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 ➜ A complicated regex Trigger

A complicated regex Trigger

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


Pages: 1 2  3  

Posted by Nexes   (65 posts)  Bio
Date Wed 01 Mar 2006 11:10 PM (UTC)
Message
Ok, say there's a line like this: Yuna Concordia, The Archsummoner is here. She wields an elemental staff in her right hand.

Now, my problem is that that line can have a line break where ever there's a space (I am not sure if it replaces the space or it's put right after it but that's not too important). For example it could look like any of these:
Yuna
Concordia, The Archsummoner is here. She wields an elemental staff in her right hand.

Yuna Concordia,
The Archsummoner is here. She wields an elemental staff in her right hand.

Yuna Concordia, The Archsummoner is here.
She wields an elemental staff in her right hand.

Yuna Concordia, The Archsummoner is here. She wields an elemental staff in her
right hand.

And so on.
I tried to make a regex pattern for it and failed miserably. I had two triggers, one for the one line version, and one for the two line version (because Mushclient doesn't like it when I make a two line trigger that's caught in one). But I can't figure out how to make the two line version work properly.

What I have so far is something like ^She( |\n)wields( |\n)(.*\n?)+( |\n)in( |\n)her( |\n)right|left hand\.$

But it still catches the one line version unfortunantly and that makes Mushclient cry. So I was wondering if anyone new some clever way of catching something like this.
Top

Posted by Nexes   (65 posts)  Bio
Date Reply #1 on Fri 03 Mar 2006 01:27 AM (UTC)
Message
I guess this is impossible. Meh.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 03 Mar 2006 06:10 AM (UTC)

Amended on Fri 03 Mar 2006 06:14 AM (UTC) by Nick Gammon

Message
Quote:

...because Mushclient doesn't like it when I make a two line trigger that's caught in one ...


Why is that?




This seemed to work for me:


<triggers>
<trigger
enabled="y"
lines_to_match="10"
match="(?s)Yuna( |\n)Concordia,( |\n)The( |\n)Archsummoner( |\n)is( |\n)here\.( |\n)She( |\n)wields( |\n)(a|an)( |\n)(.*)( |\n)in( |\n)her( |\n)(left|right)( |\n)hand\.\Z"
multi_line="y"
regexp="y"
send_to="2"
sequence="100"
>
<send>Matched!</send>
</trigger>
</triggers>


Basically I made each space into ( |\n) which then matches on the space *or* the newline. This works for me provided I don't have a space before the newline. If so, you would have to modify it a bit.

I also used the "dotall" feature ( which is (?s) at ths start) which lets the dot match on newlines, in case the line break comes inside the name of the weapon.

- Nick Gammon

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

Posted by Nexes   (65 posts)  Bio
Date Reply #3 on Fri 03 Mar 2006 11:23 PM (UTC)
Message
Ooer, I'll try that. Also, I say Mushclient doesn't like it because if it is on one line but it's a two line trigger, well, Mushclient fires the same trigger twice on the same line. It's really annoying.
Top

Posted by Nexes   (65 posts)  Bio
Date Reply #4 on Fri 03 Mar 2006 11:31 PM (UTC)
Message
If \Z is supposed to be an endline I can't use that :(

Yours is still firing multiple times on one line :(
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Sat 04 Mar 2006 01:36 AM (UTC)
Message
Quote:

If \Z is supposed to be an endline I can't use that


Why can't you use it?

From the regular expression documentation:


\Z matches at end of subject or before newline at end
\z matches at end of subject


Using \z at the end guarantees a "tail match". This stops it matching on the same line twice. Without it, if you matched over (say) 10 lines, and the line appeared twice in the 10 lines, you would get 2 matches.

Quote:

Yours is still firing multiple times on one line


It isn't firing multiple times for me. Did you change it? Using mine, it fires once per matching line. What are you testing it with? In my case I sent:


Yuna Concordia, The Archsummoner is here. She wields an elemental staff in her right hand.


I don't see how it can match multiple times, unless you have put the trigger in twice.

- Nick Gammon

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

Posted by Nexes   (65 posts)  Bio
Date Reply #6 on Sat 04 Mar 2006 02:10 AM (UTC)
Message
The thing is, the ilne doesn't end, it's part of a big paragraph. So I removed the /Z and it matches multiple times.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Sat 04 Mar 2006 09:50 AM (UTC)
Message
Well, it will do that. You expect it. If you have a regexp that might match one line, and tell it to match over 10 lines, and don't "anchor" it to the start or end of those 10 lines, then potentially you will get 10 matches, as the matching line "ripples" back through the batch of 10.

You need to find a way of anchoring it, either to the start or end of the multi-line expression.

- Nick Gammon

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

Posted by Nexes   (65 posts)  Bio
Date Reply #8 on Sat 04 Mar 2006 06:12 PM (UTC)
Message
*sigh* There's no way to anchor it. Oh well, I guess I'll just have to live with it.

I was hoping for some way to specify in the regex at at least one new line should be caught or something. It'd be nice if Mushclient itself did that so a 2 line trigger must be on two lines. But, I guess I can live with it. :p

Thanks for your help!
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #9 on Sat 04 Mar 2006 09:28 PM (UTC)
Message
I'm not quite sure what you mean by that. If you specify a multi-line trigger as matching over 2 lines, and have a newline in the regexp, then it will indeed match exactly 2 lines.

- Nick Gammon

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

Posted by Nexes   (65 posts)  Bio
Date Reply #10 on Sun 05 Mar 2006 12:57 AM (UTC)
Message
Like in your trigger example, every \n is in parentheses and a space can replace it. Therefore, if I set it as two line, I wanted it to only match if there was at least one \n in the actual matching text, not just if the regex matched.

Like say I have this trigger: Hide\n?you\n?thief
And I put it in a multiline trigger and set it to catch on two lines.

Well, it'd be nice if it did catch on two lines only.
Ie:
Hide
youthief

Hideyou
thief

But NOT:
Hideyouthief
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #11 on Sun 05 Mar 2006 01:48 AM (UTC)
Message
(hideyou\nthief)|(hide\nyouthief)

Why doesn't that work? OK, it's easy for the simple case and would be very long for the longer case, but something similar probably would work for you.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Nexes   (65 posts)  Bio
Date Reply #12 on Sun 05 Mar 2006 02:22 AM (UTC)
Message
See, the line I actually want to make this for is anything but a simple case. That's why.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #13 on Sun 05 Mar 2006 02:29 AM (UTC)
Message
OK. Let's go back to the beginning. Are you trying to extract what the summoner is wielding?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Nexes   (65 posts)  Bio
Date Reply #14 on Sun 05 Mar 2006 03:46 AM (UTC)
Message
I am trying to extract the name of every person in the room (which comes with the title sadly), and what they're wielding.

Then there are also items that are in the room that show up in the description and I want to get all those too.

Then there are NPCs that show up in the room description.

Basically, I want to grab everything useful from a big block of text.

See, when you look in Achaea it gives you something like this:
Postal Office of Hashan.
A runic totem is planted solidly in the ground. A mottled Mhojave desert falcon glides effortlessly to and fro. A sigil in the shape of a small, rectangular monolith is on the ground.
You see a single exit leading northwest.

Except when there's people in there it's more complicated, like:
The Crossroads.
Occasional drops of rain fall to the ground from a sky grey with pregnant clouds. A runic totem is planted solidly in the ground. There are 10 fierce viragos here. This shrine is crafted into the form of three tall women standing back to
back in a tight circle, hands clasped together at their sides. A sewer grate looms darkly beneath your feet. An emaciated and skeletal dracolich lurks in the shadows. Shimmering an opalescent, milky white, this iridescent pearl bears the
words "Suggestion Box" painted in flowing silver script upon its smooth surface. There are 7 mounted tsalmaveths here. A sigil in the shape of a small, rectangular monolith is on the ground. There are 4 hooded nocturnis here. A ludicrously
bright green blanket has been placed here to clash with everything. Flapping its massive wings, a dire bat flies overhead. A hefty glass mug has been left here. A flame-charred chariot pulled by demonic goats stands here. Spreading its
majestic golden wings, a giant eagle searches the ground with piercing eyes. A mottled Mhojave desert falcon glides effortlessly to and fro. A blue marble bench with a covering of dark blue satin is here. Standing on a pedestal of silver,
an Orb of Confinement has been carefully constructed here. Flaze is here, sprawled on the floor. Brother of the Red Lotus, Jasato Kuriskagi is here. He wields a steel Theran broadsword in each hand.
You see exits leading north, east, southeast, south, southwest, and northwest.
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.


89,092 views.

This is page 1, subject is 3 pages long: 1 2  3  [Next page]

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.