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:
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.
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>.
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. ^_^
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.
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. [ ].
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:
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. ^_^
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.
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.
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!
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.
I tried doing what you said Darwin and the trigger didn't fire at all. Poromenos your trigger fired perfectly except it didn't get the skill at the bottom.
My guess is it has to do with the extra space in the third skill of that row. I appreciate everyones help by the way. Once I get better at expressions I will be able to accomplish almost any task!
I'm also using VBScript and am not sure how to weed out a wildcard if it was in a place where no skill appeared and is filled with white space. I need an if condition that prevents a blank wildcard from being added to the array.
ie. if %1 not null.. or whatever it should be in this situation.
Thanks Nick that helped. I used "" for the comparison and filtering of skills into the array. Futhermore, chaging "[-a-z _]" to "[-a -z _]" resolved the issue with that line that wasn't firing. Now all I have to do is get some more data from the mud and this plugin will be nearly complete. Thanks for all the help!
Actually I should have kept my for loop test it appears, what I did there messed things up. It seems I celebrated prematurely, however I resolved the issue by using [-a-z0-9 _] instead. It now functions like it is suppose to.