Difference between revisions of "Create matcher"

From Kolmafia
Jump to navigation Jump to search
imported>Matt.chugg
(adding code sample, properly this time!)
imported>Matt.chugg
Line 23: Line 23:
 
code1={{CodeSample|
 
code1={{CodeSample|
 
title=Code Sample|
 
title=Code Sample|
description=The following code will check if you are entitled to any new trophies and if so will attempt to buy them.
+
description=The following code will check if you are entitled to any new trophies and if so will attempt to buy them.|
 
code=<syntaxhighlight>
 
code=<syntaxhighlight>
 
string trophypage = visit_url("trophy.php");
 
string trophypage = visit_url("trophy.php");

Revision as of 19:57, 13 September 2010

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");
	}
}