I was playing with PHP today creating a small language (just for fun), but I encountered a problem:
How can I select between matching brackets?
My template string:
for(items as item){ // this bracket
if(some_condition){
// do stuff
} // my regex stops here
} // and this bracket
I used this regex [\w]+\([ \w]+\){([\s\n\r\t/\w(){}]+?)}
, but it stop when finds the first closed bracket.
How can I make it select everything between his matching brackets?:
for(items as item){ // this bracket
if(some_condition){
// do stuff
} // my regex stops here
} // and this bracket
Then I will compile what's in the for
separately.
PS: Please don't post comments like "don't bother doing this" or "don't reinvent the wheel". It is just for learning purposes.