php - preg_match or operator -


my code below produces error, unknown modified "|"... i'm trying use or operator. correct way run code without error?

$p = "(\w+)|(\()|(\))|(\,)"; $s =  "sum(blue,paper,green(yellow,4,toast)))"; preg_match($p,$s, $matches); print_r($matches); 

edit

okay changed bit... ~(\w+|\(|\)|,)~

now... here's problem: need take string , split array this:

array("sum","(","blue","paper","green","(" ... etc );

can me that? when run above expression outputs empty array....

thanks

you're missing delimiter @crayon correctly mentioned, pattern same thing:

$p = '~(\w+|[(]|[)]|,)~'; 

as (new) problem, try this:

$p = '~([(),])~'; $str = 'sum(blue,paper,green(yellow,4,toast)))'; $res = preg_split($p, $str, -1, preg_split_no_empty | preg_split_delim_capture);  print_r($res); 

output:

array (     [0] => sum     [1] => (     [2] => blue     [3] => ,     [4] => paper     [5] => ,     [6] => green     [7] => (     [8] => yellow     [9] => ,     [10] => 4     [11] => ,     [12] => toast     [13] => )     [14] => )     [15] => ) ) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -