MyBB Community Forums

Full Version: Regex
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, I absolutely suck at regex. If you can help me with this I'll give you a free copy of the MyBB+ plugin it will be used in.

What is the PHP code to do find all instances of {string['anotherstring']} and for each instance store anotherstring in a new element of an array?

Thanks Smile
check out my script to update plugins for 1.6.5, sounds like what you need
"Free copy", yeah motivation! Lets try:

	preg_match_all('#'.preg_quote('{string[\'').'([0-9]+)'.preg_quote('\']}').'#i', $string, $matches); // digits?

	if(!$matches) return;

	foreach((array)$matches as $match)
	{
		$search[$match] = "{string['{$match}']}";
		$replace[$match] = get_ticked($match);
	}

	$page = str_replace($search, $replace, $page);

Random code Angel
Don't worry, it'll be a pretty in demand plugin Toungue