Jump to content

[SOLVED] How do i match several levels? (IE: "{ L1 { L2 } }" )


Cadde

Recommended Posts

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.