|
Levine Newbie
Joined: 08 Jan 2007 Posts: 3 Location: Ontario, Canada
|
Posted: Wed Jan 17, 2007 11:32 pm
Need help with multi-line regular expression |
I am trying to create a multi-line regular expression to gather room descriptions (eventually I want to feed this to the automapper somehow). The automapper's builtin handling doesn't work perfectly for me, so i've decided to try and do this myself. Anyway, I have used regular expressions for a while, mostly with perl. My understanding is that zMud uses PCRE regular expressions, and I have been using regular expressions in zMud without difficulty for single-line patterns.
Here is a sample of some text I want to match (a room description on Aardwolf):
Code: |
The Grand City of Aylor (G)
You stand on the edge of the beautiful City of Aylor.
A bright light shines down from the heavens, pouring over you, bathing you
in its warm glow. Everything around you seems rich and pure in color. An
enormous, white temple stands to the north, taking up most of your view.
To reach the Adventurer's Guild, you must travel up the large staircase that
stands just off the side of the church. (Type 'UP' to learn how to play the
game.)
Below you are large piles of armor and equipment discarded by other
adventurers.
[Exits: north east south up down]
|
All room descriptions consist of one line for the room name, an optional string "(x)" where x is a alphabetic character and always uppercase, a newline, followed by exactly two space characters, then the room desc begins. It ends with a newline followed by the Exits line. I want to capture the room name, description and exits to seperate variables, so I enclosed them in paranthesis. It seems simple enough to write a regular expression for, so I tried it:
Code: |
^([A-Z]+[A-Za-z ]+(?:\([A-Z]{1}\))?)\n( [A-Z]+[A-Za-z0-9 \n\.,'\(\)]+)\n(\[Exits: [a-z ]+\]) |
I wrote this expression with the help of a program called "The Regex Coach", which i've been using for a long time now when writing perl (PCRE) regular expressions. In this program my expression matches any room descriptions I throw at it without any problems. But in zMud I cannot get it to work, despite trying every trigger option I can think of. Currently my zMud trigger looks like this:
Code: |
#REGEX {^([A-Z]+[A-Za-z ]+(?:\(G\))?)\n( [A-Z]+[A-Za-z0-9 \n\.,'\(\)]+)\n(\[Exits: [a-z ]+\])} {#echo MATCH} "" {prompt|case|notrig} |
Can anyone tell me what i'm doing wrong?
Thanks. |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Thu Jan 18, 2007 1:36 am |
It's not you, it's ZMud--I, too, use The Regex Coach and find it to be really useful but ZMud isn't 100% PCRE... especially when it comes to an unspecified number of newlines (also things like lookahead and lookbehind, etc.).
I find that the best you can do is get the first part (which is a specific number of lines) and use that to turn on a second trigger which simply captures -everything- to a variable. Then use the end part (which again is easy to match) to turn off your capture trigger and reconstitute the lot of it as a single description.
A good feature to add (to CMud, I suppose) would be a built in capture-all-text-received-to-variable (similar to #cap on/#cap off, except to a variable and not a window). |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jan 18, 2007 4:45 am |
It's easier to use a multistate trigger with the Within parameter than it is to use mutli-line triggers. Look up the #COND command if you need more info on those. The command you're looking for to pass the data to the mapper is #TAG btw. I also suggest using the line colour option in the different states of the trigger to ensure that you get fewer false positives.
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|