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.
Entire forum
➜ MUSHclient
➜ General
➜ Matching mid line for trigger
Matching mid line for trigger
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Xavious
(41 posts) Bio
|
Date
| Sat 14 Jun 2008 12:29 AM (UTC) Amended on Sat 14 Jun 2008 02:26 AM (UTC) by Nick Gammon
|
Message
| I have constructed a plugin to automatically research skills on a swr mud that I play, however I opted to make it more effecient. Originally I created an array of 150 and put a skill into each one and created a system that loops through researching skills until they are done. Now I am trying to make the process more automated for whenever new skills are involved. The skill list looks like this:
---------------------------------Skills-----------------------------------
advanced electronics 15% aid 80% aim 95%
bash 99% beg 20% berserk 92%
blastdoor 90% call 90% chemistry 15%
claimbounty 20% construction 15% data 15%
destruction 15% dig 0% disarm 90%
dock 90% dodge 100% doorbash 0%
dual wield 100% duplicate 80% edibles 15%
education 15% electronics 90% emergency_refuel 90%
enhancearmor 90% enhanced damage 100% enhancement 15%
equipment 15% first aid 90% flurry 15%
forensics 15% gather 45% gouge 97%
grenades 80% grip 90% guidance 15%
hitall 100% jail 90% kick 100%
machines 15% makeblade 90% makecanteen 90%
makecircuit 90% makecomlink 90% makecontainer 100%
makedatapad 90% makeflashlight 90% makegoggles 90%
makeholster 90% makejewelry 90% medical 15%
minerals 15% mines 90% mount 90%
narcotics 15% navigation 100% ponder 100%
repairarmor 91% repairweapon 90% rescue 100%
research 100% scan 100% search 0%
second attack 100% ship maintenance 90% ship systems 100%
showplanet 100% small spacecraft 100% snipe 100%
spacecraft 15% study 88% survey 0%
teach 15% throw 90% torture 90%
transportation 71% tuneship 90% weapon systems 94%
---------------------------------Weapons-----------------------------------
advanced blaster 100% advanced bowcaster 90% advanced forcepike 90%
advanced vibroblade 97% blaster mastery 91% blasters 100%
bowcaster mastery 90% bowcasters 90% disruptors 90%
force pikes 90% forcepike mastery 90% unarmed combat 90%
vibro-blades 100%
To see a shorter practice list, type PRACTICE <class name>.
What I want to do is have each skill automatically put into the array for processing by a trigger, however I can't seem to get the text from each skill to match midline. I've tried * and .* and browsed through the forums for similiar problems, but I can't seem to find a solution.
Example:
bash 99% (doesn't trigger anything)
.* bash 99% (doesn't trigger anything)
/sbash 99% (doesn't trigger anything)
bash 99% beg 20% berserk 92%
(triggers just fine)
| Top |
|
Posted by
| Xavious
(41 posts) Bio
|
Date
| Reply #1 on Sat 14 Jun 2008 12:32 AM (UTC) |
Message
| I'm a newb to this forum and it seems my whitespace has been taken out for consolidation. The essence of my problem I think though is matching text midline regardless of the contents in the rest of the line. All those skills should have white space between them.. even the ones on the far left colum start out with whitespace first then the skill. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sat 14 Jun 2008 02:27 AM (UTC) |
Message
| To preserve spacing use the [code] ... [/code] tags - I have amended your post to do that. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sat 14 Jun 2008 02:45 AM (UTC) Amended on Sat 14 Jun 2008 02:47 AM (UTC) by Nick Gammon
|
Message
| What you need to do is simply take what you have explained, and put that into a regular expression.
My result is this:
<triggers>
<trigger
custom_colour="2"
enabled="y"
match="^\s*([-a-z ]+)\s+(\d+)%\s*(?:([-a-z ]+)\s+(\d+)%\s*){0,1}(?:([-a-z ]+)\s+(\d+)%\s*){0,1}$"
regexp="y"
send_to="2"
sequence="100"
>
<send>%%1 = %1
%%2 = %2
%%3 = %3
%%4 = %4
%%5 = %5
%%6 = %6
</send>
</trigger>
</triggers>
See http://mushclient.com/pasting for how to copy that into the client
Run against your test data I got:
advanced electronics 15% aid 80% aim 95%
%1 = advanced electronics
%2 = 15
%3 = aid
%4 = 80
%5 = aim
%6 = 95
bash 99% beg 20% berserk 92%
%1 = bash
%2 = 99
%3 = beg
%4 = 20
%5 = berserk
%6 = 92
... and so on ...
bowcaster mastery 90% bowcasters 90% disruptors 90%
%1 = bowcaster mastery
%2 = 90
%3 = bowcasters
%4 = 90
%5 = disruptors
%6 = 90
force pikes 90% forcepike mastery 90% unarmed combat 90%
%1 = force pikes
%2 = 90
%3 = forcepike mastery
%4 = 90
%5 = unarmed combat
%6 = 90
vibro-blades 100%
%1 = vibro-blades
%2 = 100
%3 =
%4 =
%5 =
%6 =
Basically what is happening in the regexp is for each skill:
\s*([-a-z ]+)\s+(\d+)%\s*
Which is:
- \s* --> match zero or more spaces
- ( --> start of capture group
- [-a-z ]+ --> match a-z, space or hyphen, 1 or more times
- ) --> end of capture group
- \s+ --> match one or more spaces
- ( --> start of capture group
- \d+ --> match one or more digits
- ) --> end of capture group
- % --> match the % symbol
- \s* --> match zero or more spaces
Then I copied and pasted that for the next two instances on the same line.
However as in your last line, you don't necessarily have 3 skills, I made the entire group optional, by putting the above into:
(?: .... group here .... ){0,1}
The ?: means make a non-capture group (so it doesn't become a wildcard). The {0,1} means zero or one of them (ie. it is optional). Ditto for the third group.
Then I wrapped it up between ^ .... $ which means <start of line> <something> <end of line>.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #4 on Sat 14 Jun 2008 11:18 AM (UTC) |
Message
| Nice job explaining that trigger, Nick.
Also, whereas the {0,1} is very verbose and might make it easier to understand, it can also be considered to clutter up the regexp and make it harder to see what it does. As such, you can consider the ? operator to be equivalent.
(...)? is the same as (...){0,1}
I usually prefer the shorthand ? variety, although it could be misconstrued since it is also a laziness specifier when added AFTER the repetition operator. Like: a{2,5}? or b*?
But well... that's just a bit more information because I'm bored and suffering from a headache. ^_^ | Top |
|
Posted by
| Xavious
(41 posts) Bio
|
Date
| Reply #5 on Sat 14 Jun 2008 02:43 PM (UTC) |
Message
| Thanks Nick for the quick response. I am a very big fan of MUSHclient and it's functionality and applaud you for all your work. You seem to really know what your talking about. I am an aspiring programmer as well, but I am still in my early stages of development. I think my issue with what I am trying to accomplish is that I am a novice with regular expressions. I read a help file about it included in the software, but it was a bit over my head. I will continue to research this topic, though, because I have an interest in constructing some pretty ellaborate plugins. I LOVE THAT FEATURE BTW! Plugins are amazing.. and they are conveniently packaged in XML format. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sat 14 Jun 2008 09:35 PM (UTC) Amended on Sat 14 Jun 2008 09:50 PM (UTC) by Nick Gammon
|
Message
| Thanks for your complimentary remarks, both of you. :-)
Out of interest, the regexp can be expressed a bit more readably by using the "extended syntax" option, which lets you put spaces in the middle. When you do this, to match on spaces themselves they either have to be represented as \s (whitespace) or in brackets, eg. [ ].
Here is the extended version:
match="(?x)^ \s{0,} ( [-a-z ]{1,} ) \s{1,} ( \d{1,} ) % \s{0,} (?: ( [-a-z ]{1,} ) \s+ ( \d{1,} ) % \s{0,} ){0,1} (?: ( [-a-z ]{1,} ) \s{1,} ( \d{1,} ) % \s{0,} ){0,1} $"
In the above version, for consistency, I used the {x,y} syntax, that Worstje dislikes, everywhere. It makes it wordier, I agree, but make it clearer that certain things happen a certain number of times.
To be consistent also, the version below removes that syntax and uses ? for the {0,1} case:
match="(?x)^ \s* ( [-a-z ]+ ) \s+ ( \d+ ) % \s* (?: ( [-a-z ]+ ) \s+ ( \d+ ) % \s* )? (?: ( [-a-z ]+ ) \s+ ( \d+ ) % \s* )? $"
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #7 on Sat 14 Jun 2008 09:48 PM (UTC) |
Message
| I don't dislike brackets per se, it's merely a choice and opinion. Same with where people put their brackets (line of declaration, following line, gnu-inbetween, etc).
Likewise, I'm personally no fan of lax spacing and only doing so through \s. There's two reasons for that. First is that, while \s has its advantages, it also has a rather simple 'matches whitespace' definition.. and usually when I'm using regular expressions, it is to match automated output, which means I tend to know the precise byte and such used. When I end up matching unicode and such, depending on the regex and such, it could suddenly start matching things I don't want it to. Then again, I use regular expressions for nearly everything these days, and not everybody does so. So in that sense, \s can't hurt 99.9% of the time.
Second, more realistic motivation I guess. I'm not too fond of compile time regular expression settings. As a user, I don't care what engine I use or what settings it is compiled with. I just want my regular expressions to work, and not worry about extended syntax, ignoring case and all those other options. Pretty much all of them can be accessed from within a regular expression itself using the options in a captured group, anyhow. But I digress.
I really need to go to bed some time. It beats writing these random essays on my personal choice, which don't matter since everyone has their own preferences anyhow. ^_^ | Top |
|
Posted by
| Xavious
(41 posts) Bio
|
Date
| Reply #8 on Tue 17 Jun 2008 12:54 AM (UTC) |
Message
| It seems I will have to spend some time researching regular expressions. I have read the tutorial and I only have a basic understanding at this point. I could not get your trigger match to match when I use the skill list. I tried sending a note to script and even sending a random command to the mud, but there is no indication that this match is triggering. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #9 on Tue 17 Jun 2008 03:03 AM (UTC) |
Message
| I copied and pasted your test data from above to test the regexp, so it should have fired. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #10 on Tue 17 Jun 2008 03:42 AM (UTC) |
Message
| If you still can't get it to work can you please copy and paste the exact trigger you are using (see http://mushclient.com/copying) as I suggested a couple of variations, and another sample of MUD output, which it is not firing on. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Xavious
(41 posts) Bio
|
Date
| Reply #11 on Tue 17 Jun 2008 08:22 PM (UTC) |
Message
| LOL wow.. I made a foolish error. Alright.. I just now copied your XML instead of just the trigger match and used the "paste" feature to generate the trigger and it worked perfectly. Then I realized why mine wasn't working... I forgot to check the regular expression box! | Top |
|
Posted by
| Xavious
(41 posts) Bio
|
Date
| Reply #12 on Sat 28 Jun 2008 02:47 PM (UTC) |
Message
|
Some of the lines did not fire using your test trigger and I am not certain why. Here is an example.
---------------------------------Skills-----------------------------------
advanced electronics 15% aid 82% aim 100%
%1 = advanced electronics
%2 = 15
%3 = aid
%4 = 82
%5 = aim
%6 = 100
ambush 0% backstab 0% bash 99%
%1 = ambush
%2 = 0
%3 = backstab
%4 = 0
%5 = bash
%6 = 99
beg 20% berserk 92% blastdoor 90%
%1 = beg
%2 = 20
%3 = berserk
%4 = 92
%5 = blastdoor
%6 = 90
call 90% chemistry 15% claimbounty 20%
%1 = call
%2 = 90
%3 = chemistry
%4 = 15
%5 = claimbounty
%6 = 20
conceal 0% construction 15% data 15%
%1 = conceal
%2 = 0
%3 = construction
%4 = 15
%5 = data
%6 = 15
destruction 15% diagnose 91% dig 20%
%1 = destruction
%2 = 15
%3 = diagnose
%4 = 91
%5 = dig
%6 = 20
disarm 96% dock 90% doctor 90%
%1 = disarm
%2 = 96
%3 = dock
%4 = 90
%5 = doctor
%6 = 90
dodge 100% doorbash 0% doorcut 90%
%1 = dodge
%2 = 100
%3 = doorbash
%4 = 0
%5 = doorcut
%6 = 90
dual wield 100% duplicate 80% edibles 15%
%1 = dual wield
%2 = 100
%3 = duplicate
%4 = 80
%5 = edibles
%6 = 15
education 15% electronics 90% emergency_refuel 90%
enhancearmor 90% enhanced damage 100% enhancement 15%
%1 = enhancearmor
%2 = 90
%3 = enhanced damage
%4 = 100
%5 = enhancement
%6 = 15
| Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #13 on Sat 28 Jun 2008 05:12 PM (UTC) |
Message
| By the way, a more terse regex would be:
^ *(.*?) (\d+)% *(.*?) (\d+)% *(.*?) (\d+)% *$
|
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Darwin
USA (125 posts) Bio
|
Date
| Reply #14 on Sat 28 Jun 2008 06:30 PM (UTC) |
Message
| The match failed because emergency_refuel contains an underscore which was not included in the set to match. Just change the sets from [-a-z ] to [-a-z_ ] and it should match cases like those. | 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.
59,915 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top