Page 1 of 1

Error in regular expression

Posted: Sun Nov 19, 2006 4:11 pm
by ddeschn
Hello,

I've just started getting involved with regular expressions and am getting an error I can't fix.

What I am trying to do is isolate all the text in a string that falls between '(' and ')', and also between '[' and ']'.

This is the expression that I am using:

Code: Select all

$paren = split("(?:(\()|(\[))[^()[]]*(?(1)\)|\])", $row['line']);
And the error that I get:

Code: Select all

Warning: split() [function.split]: REG_BADRPT in /home/ddeschn/public_html/chinook/index.php on line 89
Thanks for your help,
ddeschn

PS...

Example input would be:

(Said with joy.) So glad to see you! [SARCASTICALLY NOW] I am so surprised.

Output would be:

(Said with joy.) [SARCASTICALLY NOW]

Posted: Sun Nov 19, 2006 4:18 pm
by volka
try

Code: Select all

$pattern = '!\[.+\]|\(.+\)!U';
$subject = '(Said with joy.) So glad to see you! [SARCASTICALLY NOW] I am so surprised. ';
preg_match_all($pattern, $subject, $matches);
print_r($matches);

Posted: Sun Nov 19, 2006 4:18 pm
by John Cartwright
Moved to Regex.

Posted: Sun Nov 19, 2006 7:23 pm
by ddeschn
Thanks!

It worked perfectly.

ddeschn