Need the the [^ab] thing, but for strings not characters
Posted: Thu Jan 17, 2008 11:12 pm
Hi there,
I've been struggling with this seemingly simple regular expression problem. I'm hoping someone can show me how dumb I've been:
take the string {{aaa{{bbb}}ccc}}
What I need is a regex that would match the {{bbb}} part, but not the whole thing. Basically, anything in double brackets as long as it doesnt have nested stuff in double brackets within it.
The obvious solution is
m/\{{2}([^\{\}]*)\{{2}/
But the part I cant figure out is that the item matched should be allowed to contain single brackets.
eg: {{aaa{{b{bb}}ccc}} should match to "{{b{bb}}"
Basically, I need something like the [^ab] thing, but for strings ("{{" and "}}") rather than individual characters
Any suggestions?
I've been struggling with this seemingly simple regular expression problem. I'm hoping someone can show me how dumb I've been:
take the string {{aaa{{bbb}}ccc}}
What I need is a regex that would match the {{bbb}} part, but not the whole thing. Basically, anything in double brackets as long as it doesnt have nested stuff in double brackets within it.
The obvious solution is
m/\{{2}([^\{\}]*)\{{2}/
But the part I cant figure out is that the item matched should be allowed to contain single brackets.
eg: {{aaa{{b{bb}}ccc}} should match to "{{b{bb}}"
Basically, I need something like the [^ab] thing, but for strings ("{{" and "}}") rather than individual characters
Any suggestions?