Little regex problem

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

Moderator: General Moderators

Post Reply
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Little regex problem

Post 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. :)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Little regex problem

Post by AbraCadaver »

I could fix that, but I propose:

Code: Select all

$result = preg_split('/\(|\)/', $string, PREG_SPLIT_NO_EMPTY);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Re: Little regex problem

Post by dreamline »

Thanks AbraCadaver,
That would work for me too. :) So i'm going to use using preg_split instead of preg_match_all.

:)
Post Reply