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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  regex help
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

regex help

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


Posted by Fletchling   Australia  (54 posts)  [Biography] bio
Date Tue 08 Aug 2006 12:55 PM (UTC)
Message
Hi ho, I have the following problem. I can do this thing but I want to see an elegant solution, as you'll see my regex's are a bit agricultural.

mud input below;

Level: 3 Shield Mana: 5 Learned: 100% ( 72)
Mental barrier Mana: 5 Learned: 100% (126)


my regex to match this is in this trigger;

<triggers>
<trigger
group="su4"
match="^Level\:\s{1,3}(\d){1,3}(.*)Mana\:\s{1,4}(\d){0,3}\s{3}Learned\:\s{1,3}(\d+)\%\s\(\s{0,2}(\d+)\)$"
name="su4build"
regexp="y"
send_to="12"
sequence="100"
>
<send>ArrayCreate ("su4")
if %4 &gt; 72 then
ArraySet ("su4",(string.lower(Trim("%2"))),"0")
end -- if
</send>
</trigger>
</triggers>


The issue is that it only matches the first line (with shield) and I'd like it to match either case, that being the line that starts with Level: or without Level:, but I'd like to do it properly. The regex expression I've worked just plain looks ugly, I'm sure there's a better way.

This thing is part of my fast spell up script for aardwolf mud and works a treat, but I have to add some spells manually to the array (via an alias) which is fine but My crash test dummy objects to the extra effort, as she should.

As always, thanks for the help.

Fletchling
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #1 on Tue 08 Aug 2006 01:52 PM (UTC)
Message
This probably isn't any prettier, but it should work:

^(?:Level\:\s+(\d{1,3})\s)?\s*(.*?)\sMana\:\s+(\d{0,3})\s+Learned\:\s+(\d+)\%\s\(\s*(\d+)\)$
[Go to top] top

Posted by Fletchling   Australia  (54 posts)  [Biography] bio
Date Reply #2 on Wed 09 Aug 2006 10:06 AM (UTC)
Message
Ked, thanks!
That worked first go, nice!

If you ever have any annoying slimes you need killed, just send the word.
[Go to top] top

Posted by Nick Gammon   Australia  (21,669 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Wed 09 Aug 2006 10:10 PM (UTC)
Message
In fact, with regular expressions, you can use the "optional thing" syntax on not just letters (eg. [A-Z]{0,1} ) which will match an optional letter in the range A-Z but entire groups, like this:

(blah){0,1}something

This will match 'blahsomething' or just 'something'.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


3,916 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 FutureQuest]