Bug - Not A Bug calling matcher functions with $

StDoodle

Minion
Ok, I could be wrong, and stupid, it's all happened before.

But it appears that there's a java bug involving having a dollar sign in the replacement text that shows in ash when using replace_all() or replace_first().

To test, try this:
Code:
void main() {
    string s = "hello$folks";
    matcher m = create_matcher("h(.+?)s",s);
    if (m.find()) s = replace_all(m, "BOB" + m.group(1) + "BOB");
}

Now, we can get around this by replacing all dollar signs (using the matcher "\\$") and replacing them with "\\\$" and then they'll be properly escaped once they're actually used in a write() call, but we'll still see the backslash on a print().

Any thoughts on a general solution that doesn't involve changing a string around based on where it's going would be appreciated. Or feel to point out something that should be obvious that I'm missing; that's entirely possible.
 
Last edited by a moderator:

holatuwol

Developer
Is there any reason you don't use:

PHP:
void main() {
    string s = "hello$folks";
    matcher m = create_matcher("h(.+?)s",s);
    if (m.find()) s = replace_all(m, "BOB$1BOB");
}
 

holatuwol

Developer
It's for when you need to extract data, rather than replace it. Same reason we use it all over the place in KoLmafia source. =)

Edit: Might be clearer with an example. An example that I worked with recently is in AccountRequest. Say we're parsing the page and we want to figure out what skill you're currently defaulting for auto-attack. We just pass in a regular expression and use group() to get out the skill id and store it in a variable. Now that it's been extracted, we can manipulate it (for example, turn it into an int), call functions related to it (like looking up the skill name from the int value). Similar things happen when we parse the inventory just to grab data.
 
Last edited:
Top