Create matcher: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Matt.chugg
No edit summary
imported>Ulti
improving navigation
 
(One intermediate revision by one other user not shown)
Line 28: Line 28:
matcher trophymatcher = create_matcher("name\=whichtrophy.*?value\=(.*?)\>",trophypage);
matcher trophymatcher = create_matcher("name\=whichtrophy.*?value\=(.*?)\>",trophypage);
while (find(trophymatcher)){
while (find(trophymatcher)){
if (my_meat() >= 10000) {
  if (my_meat() >= 10000) {
string buytrophy=visit_url("trophy.php?action=buytrophy&whichtrophy="+group(trophymatcher,1),true);
      string buytrophy=visit_url("trophy.php?action=buytrophy&whichtrophy="+group(trophymatcher,1),true);
} else {
  } else {
print("Not enough meat","red");
      print("Not enough meat","red");
}
  }
}
}
</syntaxhighlight>}}|
</syntaxhighlight>}}|


 
see_also={{SeeAlso|find|replace_all|replace_first}}|
}}
}}



Latest revision as of 17:12, 14 October 2014

needs(code_samples);

Function Syntax

matcher create_matcher(string regex ,string input )

  • regex is the regular expression to use
  • input is the string to search with a regular expression

Creates a matcher from a pattern and input string.

Code Sample

The following code will check if you are entitled to any new trophies and if so will attempt to buy them.

string trophypage = visit_url("trophy.php");
matcher trophymatcher = create_matcher("name\=whichtrophy.*?value\=(.*?)\>",trophypage);
while (find(trophymatcher)){
   if (my_meat() >= 10000) {
      string buytrophy=visit_url("trophy.php?action=buytrophy&whichtrophy="+group(trophymatcher,1),true);
   } else {
      print("Not enough meat","red");
   }
}

See Also

find() | replace_all() | replace_first()