Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
eriko
Forum Newbie
Posts: 2 Joined: Mon Jan 15, 2007 1:15 pm
Post
by eriko » Mon Jan 15, 2007 1:49 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 15, 2007 1:55 pm
eriko
Forum Newbie
Posts: 2 Joined: Mon Jan 15, 2007 1:15 pm
Post
by eriko » Tue Jan 16, 2007 4:06 am
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 16, 2007 2:54 pm
Unfortunately regular expressions don't handle recursion well. No matter what you will have to analyze the output.
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Wed Jan 17, 2007 9:18 am
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?