Jump to content

[SOLVED] REGEX


Minase

Recommended Posts

hy there i have the following text

 

(game (name test) (valueb something) 
(etc) (etc) 
(etc))  

(game (name test2) (valueb something) 
(etc) (etc) 
(etc))  

// this is just a 3 line example ,it can be on 1 line or on 10
//thats how a doccument will look,i need to group everything from "(group till the two ))" anyone know how i can do this with regex?
thank you

Link to comment
https://forums.phpfreaks.com/topic/139597-solved-regex/
Share on other sites

so you want to capture this:

 

(game (name test) (valueb something)

(etc) (etc)

(etc))

 

Do you want to capture it as just 1 string of info, or each individual (...)? Your example has two sets of those things; will your document have more than 1, and do you want to capture those, as well?

 

Link to comment
https://forums.phpfreaks.com/topic/139597-solved-regex/#findComment-730571
Share on other sites

or

<?php
$test = '(game (name test) (valueb something) 
(etc) (etc) 
(etc))  

(game (name test2) (valueb something) 
(etc) (etc) 
(etc))  

// this is just a 3 line example ,it can be on 1 line or on 10
//thats how a doccument will look,i (need to group everything from "(group till the two ))" anyone know how i can do this with regex?
thank you';
$len = strlen($test);
$out = array();
$count = 0;
$part = '';
for ($i = 0; $i < $len; $i++){
if ($test[$i] == ')') $count--;
if ($count > 0) $part .= $test[$i]; elseif ($part){
	$out[] = $part;
	$part = '';
}
if ($test[$i] == '(') $count++;
}
print_r($out);
?>

Link to comment
https://forums.phpfreaks.com/topic/139597-solved-regex/#findComment-730690
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.