Page 1 of 1

Little regex problem

Posted: Sat Jan 09, 2010 10:20 pm
by dreamline
Hi All,
I am running into a little regex problem. Here's an example of what I have sofar:

Code: Select all

 
$string = "title(mytest)";
preg_match_all('/.*?[^\()]+/i',$string,$matches);
 
It's probably simple what I want to do. All I want is the text to split title and mytest into 2 arrays without the parenthesis. What I have now on code outputs:
title
(mystest

So I basically would like to know how i can get that final ( out of my output.

Help is highly appreciated. :)

Re: Little regex problem

Posted: Sun Jan 10, 2010 10:07 am
by AbraCadaver
I could fix that, but I propose:

Code: Select all

$result = preg_split('/\(|\)/', $string, PREG_SPLIT_NO_EMPTY);

Re: Little regex problem

Posted: Sun Jan 10, 2010 8:05 pm
by dreamline
Thanks AbraCadaver,
That would work for me too. :) So i'm going to use using preg_split instead of preg_match_all.

:)