Difference between revisions of "Create matcher"

From Kolmafia
Jump to navigation Jump to search
imported>Matt.chugg
(add code sample)
imported>Matt.chugg
(fix messed up code sample)
Line 20: Line 20:
  
 
needscode=yes|
 
needscode=yes|
 
}}
 
 
  
 
code1={{CodeSample|
 
code1={{CodeSample|
Line 38: Line 35:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
}}
 +
 +
 +
  
 
[[Category:String Handling Routines]]
 
[[Category:String Handling Routines]]

Revision as of 19:52, 13 September 2010

{{

FunctionPage| name=create_matcher|

function1=

matcher create_matcher(string regex ,string input )

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

|

function_description=Creates a matcher from a pattern and input string.|

needscode=yes|

code1=

Code Sample

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

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

{{{code}}}