Register forum user name Search FAQ

Gammon Forum

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 ➜ Programming ➜ General ➜ Help!! I'm in regular expression hell!

Help!! I'm in regular expression hell!

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Bottomfeeder   (42 posts)  Bio
Date Thu 21 Aug 2008 06:24 PM (UTC)
Message
So I've been banging my head against the regular expression wall and would appreciate some help untangling my brain. What we have here is a trigger match line that follows:

match="^\s*(\s*|\(\s*(\d{1,})\))\s*((\((Blue Aura|Invis|Glow|Hum|Magic|([KBIGHM]))\)){0,})\s*(@buffdesc)\s\[\d{1,3}\]\s*$"

Now the text it should be triggering on is:
"(26) (Magic) (Glow) (Hum) a Refreshing Idea (100)"

-(26) is the quantity and when there's only 1 it won't be present.

-(Magic) (Glow) and (Hum) aren't always all present

-a Refreshing Idea is loaded into the variable @buffdesc

-(100) is the level of the item and will always be there and an integer although not always 100.


So could someone please tell me not understanding with the regular expression? It just won't trigger.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #1 on Thu 21 Aug 2008 07:53 PM (UTC)

Amended on Thu 21 Aug 2008 08:18 PM (UTC) by Worstje

Message
.. That thing gives me a headache as well. Rather than trying to fix it, I'm going to start from scratch. This thing has so many places it can go wrong at, and the fact that it clearly triggers more things than you've explained isn't really helping me figure out what parts are correct and what aren't.

First of all, there's no other trigger which may be interfering? If another trigger (same or lower sequence) matches a line and does not have keep_evaluating="y" then your trigger will never even be attempted.

Second, my attempt to match your data follows after this. I am going to assume you are only interested in the number(s) in the data. One problem I can see is that you try to repeat a group with varying contents (the affects), which should work but can pose a problem if you actually want to use the data you are triggering on since only the last repetition will be captured. For now, I'll leave that part be - simply because I want to try to make the trigger as simple as possible.

^\s*(?:\((\d+)\)\s*)?(?:\(\w+)\)\s)*(.*)\((\d+)\)$

Wildcards are filled with:
[1] = quantity
[2] = last occurrence of an affect
[3] = item description
[4] = level of item

You can use a simple script with SetVariable(), or a '%3' combined with 'Send to: Variable' to get the item description in your buffdesc variable.

I hope it helps you a bit. :)
Top

Posted by Bottomfeeder   (42 posts)  Bio
Date Reply #2 on Thu 21 Aug 2008 08:37 PM (UTC)
Message
You sir, are a gentleman and a scholar! I'm still very green and regular expressions make me wanna kick things, hard.

Thank you for cleaning that up.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #3 on Thu 21 Aug 2008 09:08 PM (UTC)
Message
I'm glad I could help. Feel free to ask again when you run into some issues. =)
Top

Posted by Bottomfeeder   (42 posts)  Bio
Date Reply #4 on Fri 22 Aug 2008 03:34 PM (UTC)

Amended on Fri 22 Aug 2008 03:35 PM (UTC) by Bottomfeeder

Message
Not sure if you're still around, but could you look this over and tell me how it looks?

To trigger off of either one of these:
You buy 2 * Jade Elixir from Jojobo for 1920 gold.
You buy Jade Elixir from Jojobo for 1920 gold.

I am using:
You buy(\s(\d+)\s\*)|\s(?:@healdesc) from \w+ for \d+ gold.

The only thing I'm worried about getting into wildcards is the first \d+. Which, unless I'm wrong, should go into wildcards[2].

Everything else can be matched and discarded.

I can only get it to match on the single purchases, any purchase with multiple Elixirs doesn't fire.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #5 on Fri 22 Aug 2008 03:46 PM (UTC)

Amended on Fri 22 Aug 2008 05:27 PM (UTC) by Worstje

Message
Hrm, let's see. I'll start from scratch again since I prefer it over fixing someone elses regular expression (and I'm a bit sleepy...)

^You buy (?:(\d+) \* )?(.*?) from (\w+) for (\d+) gold\.$


Wildcards:

[1] amount (may be empty)
[2] item description
[3] salesperson
[4] spent gold


I hope that helps you a bit. :)

Edit: made a minor mistake. Fixed now.
Top

Posted by Bottomfeeder   (42 posts)  Bio
Date Reply #6 on Fri 22 Aug 2008 05:02 PM (UTC)
Message
Man oh man, this has been a crash course in regular expression but I think I am finally getting the hang of them now. Thanks for the help Worstje.

I ended up using the following syntax...

You buy((\s(\d)\s\*\s)|\s)(?:@healdesc) from \w+ for \d+ gold.$

With wildcards[3] being filled with the number of potions bought on a multiple item purchase.

They are really quite handy but wrapping my head around them has been a challenge. Once again, seeing your method has been invaluable, thank you.
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.


18,576 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.