extract method arguments

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

Moderator: General Moderators

Post Reply
eriko
Forum Newbie
Posts: 2
Joined: Mon Jan 15, 2007 1:15 pm

extract method arguments

Post by eriko »

Hi

I have a string in the following format

function(arg1,arg2,arg3)

the arguments are simple [\w\d]+ but i cant find a simple way to extract them because of the comma

Any clues?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

eriko
Forum Newbie
Posts: 2
Joined: Mon Jan 15, 2007 1:15 pm

Post by eriko »

That is not enough since an argument can be another function thus explode splits the string in a bad way.

func(func(A,B), B)

with explode

func(A
B)
B

i want

func(A,B)
B
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Unfortunately regular expressions don't handle recursion well. No matter what you will have to analyze the output.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

You have to build a tokenizer for your language, parsing recursive syntax trees with regular expressions won't do, as feyd pointed out.
What are you trying to accomplish, isn't there an easier way to do it? If you need a "scripting" language, why not use PHP itself?
Post Reply