|
HariKari Wanderer
Joined: 16 Feb 2001 Posts: 57
|
Posted: Fri Dec 20, 2002 3:41 am
Pattern Matching - Fixed Length String |
Is there an easy way to match a fixed length "string" that can be made up of two characters.
Something like..
XXXXXXAAAAAAA
XXXXXXXXXXXXX
AAAAAAAAAAAAA
The X's will always come before the A's. I don't care what they are (if they are X or A's) I'm just matching it.
Right now I'm just using a string of X's because I'll always see full X's, but for other people, they might see X's and A's.
I can only think of using a bunch of ?'s or a bunch of {A|X}'s.
This isn't really that important but I'm just curious how someone else would do it. |
|
|
|
Drevarr Beginner
Joined: 19 Dec 2001 Posts: 17 Location: USA
|
Posted: Fri Dec 20, 2002 4:30 am |
#trigger {([XA])} {#if %len( %1)=13 {#Show Matched the line}}
|
|
|
|
HariKari Wanderer
Joined: 16 Feb 2001 Posts: 57
|
Posted: Fri Dec 20, 2002 7:53 am |
Anybody know how efficient that would be? But I guess that isn't that big of an issue with faster computers/faster zMUD 6.40
|
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Dec 20, 2002 1:59 pm |
I devised a quick test for this. First I created three triggers, one for each method:
#TRIGGER {(?????????????)} {#ADD test 1}
#TRIGGER {({X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A}{X|A})} {#ADD test 1}
#TRIGGER {([XA])} {#IF (%len(%1) = 13) {#ADD test 1}}
Then, I created a text file in which the first and last line were both:
#SH %secs
In between those two lines there were a bunch of #SH's. The upper block and lower block of #SH's contained a sentence that would not be matched by the triggers. While the middle block of #SH's contained:
XXXXXXAAAAAAA
I then put this file in the zMUD folder and disabled both of the other triggers except the one I wanted to test (this was done in a blank window in which the only triggers were the three I created) and entered:
#VAR test 0;#READ speedtest.txt
This was repeated again for the other two (keeping always the ones not to be tested disabled).
Anyway, this is just in case you wanted to reproduce the test yourself. In the end, I obtained a difference between the last and first %secs for each one as follows:
Trigger 1 - 942ms
Trigger 2 - 831ms
Trigger 3 - 1002ms
So, it appears that the second method (13 {X|A}'s) is the faster one.
Kjata |
|
|
|
HariKari Wanderer
Joined: 16 Feb 2001 Posts: 57
|
Posted: Sat Dec 21, 2002 8:17 am |
Ok, thanks for the testing info.
I was thinking that specific data would be faster than using variables, but I wasn't too sure.
Thanks again. |
|
|
|
|
|