Welcome to WebmasterWorld Guest from 54.158.36.59

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg match all question

     
10:07 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



Hi guys,

Got a question about preg_match_all. I'm using preg_match_all to fetch all the items in a text which are between curly brackets. There is one problem ... sometimes there are curly brackets between other curly brackets.

Here is an example:
preg_match_all works with this one {bla}{bla}{bla}
but not with this one {bla{bla}bla}

This is the code I use
preg_match_all('/\{(.+?)\}/ims',$article,$itemis);

Any suggestions ?

10:09 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What would you like the output to be when that happens?
10:18 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



if this is the input {bla1{bla2}bla3} then I would like to have this 'bla1{bla2}bla3' and this 'bla2' as output
10:30 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



is this possible ?
11:10 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



getting a headache of this one :-/ somebody ?
11:39 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I just answered a very similar question yesterday in the Perl forum. You can use recursion [webmasterworld.com] to match nested patterns.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month