Cadde Posted December 15, 2006 Share Posted December 15, 2006 I found a sollution to my previous problem quoted below![code=PHP CODE] $Pattern = "/#\s*(?P<Function>[^#]+?)\s*\((?P<Params>[^)]*?)\)\s*#\s*{(?P<Block>[^{]*?)}/is"; $Result = Preg_Match_All($Pattern, $Subject, $Matches, PREG_OFFSET_CAPTURE);[/code]It will match the function inside the function first, i would then handle that function first obviously and strip it from the subject and keep matching until there is nothing left to match.Or as my question was in the first place, how would i match several levels... ( {{}} )I would simply have a work string that replaces any "insider functions charachters "#", "{", "}" with a "useless" byte and keep going until i am at the bottom level with no more matches!Sorry if im unclear, i've been at this problem for a long time now and i just bumbed into it by chance really.//Cadde[quote="Old Message"]Hi, i've been trying to work this out for a very long time now but i cant work it out...[b]I have a string that contains:[/b][code]First non block.# Setup() # { §Num = 0; §Bool = True; §String = "A string"; }Second non block.# ForEach(§ArrayVar As §ArrayKey => §ArrayValue) # { §ArrayVar[§Arraykey] is §ArrayValue. # For(§Counter = 1; §Counter <= 10; §Counter++) # { Counted §Counter items for fun! } And now we counted to ten as well :) (To keep ourselves from going bold with regexes) }Third and final non block.[/code]Now what i want is to match the first section:#*#{***}And i want to match the second section that follows this pattern:#*#{***#*#{***}***}Do you understand at this point???Great!Can you help me produce a pattern that can catch the equal ammounts of "{" as "}" so that i can have the full function?If you didnt get it i will try to be more detailed...So i want to be able to capture functions just like they would appear in PHP with the small diffrence that instead of:Function Foo() { ... }It is...# Foo() # { ... }And if the function contains other function i want them ignored until later...My patterns can only capture function that doesn't have functions inside them...My pattern can only capture this for example:[code]# Foo() # { # Bar() # { DoStuff... }[/code]You see my problem now? There is a curlybrace missing, i want it to capture the whole function start to end...Please be of assistance :)THANK YOU!//Cadde[/quote] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.