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
➜ regex help
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Fletchling
Australia (54 posts) 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 > 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 | Top |
|
Posted by
| Ked
Russia (524 posts) 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+)\)$
| Top |
|
Posted by
| Fletchling
Australia (54 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 | 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.
14,547 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top