|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Tue Feb 22, 2005 6:56 pm
Regex question |
Hello all,
Im working on something and was wondering if someone could give a bit o advice. What Im trying to accomplish is using #regex to find all matching words, create a trigger for each word that would highlight them. I know it can be done without #regex such as the Achaean Highlight City Enemies script. The problem is there isnt a specific number of lines or number of items on each line.
Ive been able to highlight each entry, but that only applies to when I run #regex to scan the line.
#REGEX {\w+} {#cw 12} <-- highlights, and works for each word.
what Id like is something along the lines of
#REGEX {\w+} {#trigger {%1} {#cw 12}} <-- doesnt work, and only picks up the first word. Ive tried changing around the %1 to %w and $1 \w none of which work. There are over 200+ items in this block of text.
Heres a sample of the output from the MUD
Broom, Handle, Bat, Ball, Stick, Hammer
, Item1, item2, etc, etc, etc
Is it possible to use #regex to apply each matched pattern to a variable or to create a trigger from each matched pattern?
Sorry its all long winded. Another idea I had was would it be faster and less intensive to use a string list and highlight each entry that way or just use triggers?
Thanks |
|
|
|
jessew Apprentice
Joined: 03 Mar 2003 Posts: 141
|
Posted: Tue Feb 22, 2005 10:06 pm |
Leave out the parenthesis for the capture?
#REGEX {(\w+)} {#TRIGGER {%1} {#cw 12}} |
|
_________________ I love deadlines. I like the whooshing sound they make as they fly by. |
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Tue Feb 22, 2005 10:20 pm |
Doing it that way, creates a global trigger with the pattern of (\w+) and value of #TRIGGER {broom} {#cw 12} {testing} and puts a trigger for broom in my testing folder. It only works for the first word of the line and makes two triggers that does the same thing...
Ive done (\w+,*\s*) hoping that it would grab the name, a possible comma, and possible space and then move on to the next word.
I guess what Im after is something that'll go down the line grabbing each word and passing it off to create a trigger. Something like %1++, where it'll increase %x each time regex grabs a word. |
|
|
|
Maelstrom Apprentice
Joined: 10 Feb 2005 Posts: 158
|
Posted: Wed Feb 23, 2005 12:25 am |
I dont have enough log information, but if you grab the whole line at once (maybe ending but not including the period? if there is one) then this can be done in a slightly more complicated manor. More'n one way to skin the cat yes?
Example trigger (needs to be modified to work so you only get the list of items):
#TRIGGER {(*)~.} {#FORALL {%replace( "%1", ", ", "|")} {#TRIGGER {%i} {{#cw 12}}}
This about what your looking for?
|
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Wed Feb 23, 2005 12:51 am |
Heres a sample of what Im trying to work with... each item has a different name
item, item, item, item, item, item, item, item, item
, item, item, item, item, item, item, item, item, item,
item, item, item, item, item, item, item, item, item
Total: xx
Its strange because the first line starts with a name, but beyond that, its random as to whether or not the start of the line starts with a name or a ", name". The only way to tell that its the end is Total: xx |
|
|
|
Aarlot Adept
Joined: 30 Dec 2003 Posts: 226
|
Posted: Wed Feb 23, 2005 1:32 am |
Something like:
#TRIGGER "itemcap" {^(*)} {#IF (%begins( %1, "Total:")) {
#T- itemcap
#VAR itemline %replace( @itemline, ", " "|")
} {#VAR itemline %concat( @itemline, %1)}} "" {disable}
#TRIGGER {PUT TEXT THAT DENOTES START OF ITEM LIST HERE} {
#T+ itemcap
#VAR itemline {}
}
From what you gave me, it looks like this might work, if there is some sort of starting text you can trigger off of to turn this on |
|
_________________ Everyone is entitled to their beliefs - until they die. Then only the truth matters. |
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Wed Feb 23, 2005 4:41 am |
Well, using your triggers, it sucessfully plugs every item into the variable @itemline. Now if I can figure out a way to create a trigger for each individual item and highlight it.... Thanks Aarlot, Ill play around with your code.
|
|
|
|
Maelstrom Apprentice
Joined: 10 Feb 2005 Posts: 158
|
Posted: Wed Feb 23, 2005 4:15 pm |
You can use part of my original posting for this...
#FORALL {@itemline} {#TRIGGER {%i} {#cw 12}}
Cheers! |
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Wed Feb 23, 2005 6:24 pm |
Not sure if I plugged it in the right place...
trigger pattern: ^(*)
value:
#IF (%begins( %1, "Total")) {
#T- itemcap
#VAR itemline %replace( @itemline, ", ", "|")
} {
#VAR itemline %concat( @itemline, %1)
#FORALL {@itemline} {#TRIGGER {%i} {#cw 12}{testing}}
}
That creates two triggers, one for the first line and then another for the first line concat'd with the second.... Im trying to get a trigger for each item, not a string of each concat'd together if that makes sense? |
|
|
|
Maelstrom Apprentice
Joined: 10 Feb 2005 Posts: 158
|
Posted: Wed Feb 23, 2005 8:12 pm |
Actually it wouldnt go in any of those if I am reading it right. You would put it after the list is complete.
Perhaps like this:
#TRIGGER {^Total: %d$} {#FORALL {@itemline} {#TRIGGER {%i} {#cw 12}} |
|
|
|
Aarlot Adept
Joined: 30 Dec 2003 Posts: 226
|
Posted: Thu Feb 24, 2005 12:34 am |
If you're just going to color them all the same, why make all of those different triggers? Why not just:
#TRIGGER {({@itemlist})} {#CW 12}
|
|
_________________ Everyone is entitled to their beliefs - until they die. Then only the truth matters. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Feb 24, 2005 1:30 am |
Speed. With lots of settings, a really long and drawn-out trigger is going to bog down more easily. If it hangs long enough, ZMud actually kills the process or otherwise interferes with the output (in really scrolly situations, some triggers appeared to not even fire).
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Thu Feb 24, 2005 2:03 am |
the problem maelstrom, when i used those lines of code, is that it creates 1 trigger with the pattern of item1item2item3item4... And when i use the #VAR itemline %replace( @itemline, ", " "|") the pipe doesnt appear after the trigger has been fired and finished.... any more suggestions?
I greatly appreciate everyones help...
well after reading more about the #forall, it requires the pipes... which arent coming thru... the value for that trigger is:
#IF (%begins( %1, "Total")) {
#T- itemcap
#VAR itemline %replace( @itemline, ", ", "|")
} {
#VAR itemline %concat( @itemline, %1)}
Sorry if Im not clear enough... I check the contents of the variable itemline, it just lists all of the items concat'd together. I tried changing the | to other characters to see if it would come thru and it doesnt. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Feb 24, 2005 6:03 am |
Does the itemcap trigger properly fire and disable? If it doesn't disable, your problem is in the #IF condition. I don't see anything untoward in it, unless some of your items are more than one word long. If so, the space between the first word and the second word might be confusing the parser. To fix, just surround %1 in that function with double quotes. This ensures that the whole item is treated as one entity.
The other thing that could be happening is that your item list is just long enough that the %replace() can't keep up with trigger execution. This can throw off your trigger pretty badly, sometimes even preventing code from even executing! To fix this problem you might need to surround that #var command with a #PRIORITY. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Thu Feb 24, 2005 6:33 am |
My IF condition works out, tested it with an echo. I thrw the #priority around the #var itemline %replace line and same thing still occurs... One thing I did notice was when I let my mouse hover over the ", " in the replace line it states =", and when I let it hover over the "|" it just states = Dunno if that helps any? I checked my special char settings to see if it was used in there and it is not...
Thanks again all... I greatly appreciate all of your advice!!
Heres where the code is at now:
Code: |
#TRIGGER {List of items:%crlf} {#VAR itemline "" "" {testing};#T+ itemcap} "testing"
#TRIGGER "itemcap" {^(*)} {#IF (%begins( %1, "Total:")) {#T- itemcap;#VAR itemline %replace( @itemline, ", ", "|")} {#VAR itemline %concat( @itemline, %1)}} "testing" {disable}
#TRIGGER {^Total: %d$} {#FORALL {@itemline} {#TRIGGER {%i} {#cw 12} {testing}}} "testing" |
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Thu Feb 24, 2005 9:54 am |
The problem is simply a lack of delimeters. The %nn variables are expanded early. This means they are substituted directly into the script prior to parsing.
In the code you have:
#TRIGGER "itemcap" {^(*)} {#IF (%begins( %1, "Total:")) {#T- itemcap;#VAR itemline %replace( @itemline, ", ", "|")} {#VAR itemline %concat( @itemline, %1)}} "testing" {disable}
%1 gets filled and the script look like this when parsed:
#TRIGGER "itemcap" {^(*)} {#IF (%begins( , item, item, item, item, item, item, item, item, item,, "Total:")) {#T- itemcap;#VAR itemline %replace( @itemline, ", ", "|")} {#VAR itemline %concat( @itemline, , item, item, item, item, item, item, item, item, item,)}} "testing" {disable}
This results in %begins possibly reading true when you don't want it to. The %concat parses off the comma as seperators and eliminates the spaces next to them which totally ruins the original list.
The correct way to do it is use quotes around the %1 references:
Code: |
#TRIGGER "itemcap" {^(*)} {#IF (%begins( "%1", "Total:")) {#T- itemcap;#VAR itemline %replace( @itemline, ", ", "|")} {#VAR itemline %concat( @itemline, "%1")}} "testing" {disable} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Tittering_Leo Newbie
Joined: 22 Feb 2005 Posts: 9
|
Posted: Thu Feb 24, 2005 5:37 pm |
Thank you sooo much!!! It works now! I had to add another replace line to handle a , and crlf so this is how it looks now
Code: |
#TRIGGER "itemcap" {^(*)} {#IF (%begins( "%1", "Total:")) {#T- itemcap;#VAR itemline %replace( @itemline, ", ", "|");#VAR itemline %replace( @itemline, ",", "|")} {#VAR itemline %concat( @itemline, "%1")}} "testing" {disable} |
Thank you everyone for your help! |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|