Page 1 of 1

I want to allow anything between parantheses but not '-'

Posted: Wed Feb 01, 2006 8:27 am
by raghavan20
I am trying to extract character between brackets...but I do not want text within brackets which has hyphen in it.

Code: Select all

<?php

$input = <<<EOD
Character data is roughly all the (non-markup) contents of XML documents, including whitespace between tags. 

Note that the XML parser does not add or remove any (whitespace), it is up to the application (you) to decide 

whether whitespace is significant. 
EOD;
echo preg_match_all("/\(([^-].*?)\)/mi", $input, $matches)."<br />";
print_r($matches);

?>
The non-markup is matched but it should not be...
output:

Code: Select all

Array
(
    [0] => Array
        (
            [0] => (non-markup)
            [1] => (whitespace)
            [2] => (you)
        )

    [1] => Array
        (
            [0] => non-markup
            [1] => whitespace
            [2] => you
        )

)

Posted: Wed Feb 01, 2006 9:18 am
by feyd

Code: Select all

#\(([^-]*?)\)#