Everyone loves RegEx

me259259

Member
I'm currently writting a script to read the raid log to automatically set my choice adventures for me. Right now, I'm working on burnbarrel blvd., deciding when to violently throw a tire on the fire. When to throw a tire violently will depend on how many hobos are left in the area.

Here's what I'm trying:

PHP:
parser = create_matcher("defeated Hot hobo x (\\d+)", page_text) ;
	while(parser.find())
		hotHobosDefeated += parser.group(1).to_int() ;

But it is unable to count how many hobos are left in the area. I don't get an error message, it just returns 0, (even when there have been hot hobos defeated).

I went to www.regexplanet.com to test my expression, and it works fine there. What am I doing wrong?
 

xKiv

Active member
1) Did it work fine on the exact text of the dungeon log page?
2) Are you certain that's exactly the correct capitalization and amount of spaces?
3) this is even more speculative, but you might want to try escaping the parentheses (as in ... "\\(\\d+\\)" . Not all regex engines have all magic characters enabled by default.
 

heeheehee

Developer
Staff member
1) Did it work fine on the exact text of the dungeon log page?
2) Are you certain that's exactly the correct capitalization and amount of spaces?
3) this is even more speculative, but you might want to try escaping the parentheses (as in ... "\\(\\d+\\)" . Not all regex engines have all magic characters enabled by default.

re #3: ASH regex are just passed directly to Java, which claims to be PCRE, so this isn't an issue.

Also, there might not be a space after the x; I don't remember.
 

xKiv

Active member
re #3: ASH regex are just passed directly to Java, which claims to be PCRE, so this isn't an issue.

I knew they are passed directly to Java, but I never remember which way it goes in which engine.
Well, except VIM, which I used a lot recently, but will forget it soon now that I made that into a macro.

ETA: oh, replacing the spaces with \\s* (any whitespace or nothing) might be a good thing.
 

Theraze

Active member
Bottom line is if you want help on this, best thing you can do is paste some sample "what you're trying to match" directly from your system. :) Helps even more than giving us the regexp you're currently using...
 

me259259

Member
heeheehee was right. There are 2 spaces between "defeated" and "hot" in the html. When I copied the raid log to regexplanet, it only copied one space, which is why it worked there, but not with mafia. I'll use \\s* to prevent invisible whitespace from thwarting me again.

New expression:
PHP:
"defeated\\s*Hot\\s*hobo\\s*x\\s*(\\d+)"

Thank you everyone!
 

StDoodle

Minion
Yeah, for future information, there are invisible ('cause HTML is supposed to ignore them) double-spaces all over KoL. While it makes for some ugly, convoluted expressions, I tend to use \\s* or \\s+ whenever I deal with KoL HTML. Unless I'm being lazy. So, I use them about half the time.
 
Top