[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Regexp Syntax trouble

Regexp Syntax trouble

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


Posted by tobiassjosten   Sweden  (79 posts)  [Biography] bio
Date Wed 27 Apr 2005 08:41 PM (UTC)
Message
I'm trying to match these lines:
You quickly eat a wormwood root.
You quickly eat a nightshade root.
You quickly eat a galingale flower.
You quickly eat a piece of kelp.
You quickly eat a mandrake root.
You quickly eat an orphine seed.
You quickly eat a maidenhair leaf.	
You quickly eat some hyssop stem.
You quickly eat a juniper berry.

And I want a wildcards["herb"] command being sent to a function of mine, containing the actual herb I ate. The herbs are: wormwood, galingale, kelp, mandrake, orphine, maidenhair, hyssop and juniper. Is this even posible with one line of regexp? I could do it in two triggers, one seperate for the kelp-line, but that'd look oogley. :P So far I've got:
You quickly eat (a|an|some)(.|piece of.)(?P<herb>\w+)(\.|root\.|flower\.|seed\.|leaf\.|stem\.|berry\.)$

But it doesn't react, at all..

Simplicity is Divine | http://nogfx.org/
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #1 on Wed 27 Apr 2005 09:08 PM (UTC)

Amended on Wed 27 Apr 2005 09:12 PM (UTC) by Flannel

Message
^You quickly eat (an?|some)( piece of)? (?P<herb>\w+)( (root|flower|seed|leaf|stem|berry))?\.$

You forgot to allow for a space between a/an/some and piece of and the herb and your list of types (stem, etc).
But that Regexp up there works, and is more efficient (doesn't have all the redundant periods, or the alternate method of doing piece of. Get comfortable with '?' for optional it is indeed your friend).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by tobiassjosten   Sweden  (79 posts)  [Biography] bio
Date Reply #2 on Wed 27 Apr 2005 09:18 PM (UTC)
Message
You're a savior! ;) So, the ?-mark matches .. what again?

Simplicity is Divine | http://nogfx.org/
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #3 on Wed 27 Apr 2005 09:30 PM (UTC)

Amended on Wed 27 Apr 2005 09:32 PM (UTC) by Flannel

Message
the ? mark tells whatever is IMMEDIATELY infront of it to match 0 or 1 times.

so like, "an?" match a or an (1 or 0 'n's), and then when you do it on a group like ( piece of)? it says "look for the group ' piece of 0 or 1 times".
The same thing at the end (the group directly infront of the ? includes the group of alternates, as well as the space infront of them).

Quantifier rundown:
* is 0 or more, + is 1 or more, ? is 0 or 1
so, .* is equivalent to .+? (0 or 1 of 1 or more items)
You can do the same with brackets: {0,} (*), {1,} (+), {0,1} (?), and then that allows you to get even more specific with things like: {3,6} (between three or six).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] 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.


13,041 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]