Error in regular expression

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
ddeschn
Forum Newbie
Posts: 2
Joined: Sun Nov 19, 2006 4:00 pm

Error in regular expression

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Regex.
ddeschn
Forum Newbie
Posts: 2
Joined: Sun Nov 19, 2006 4:00 pm

Post by ddeschn »

Thanks!

It worked perfectly.

ddeschn
Post Reply