Page 1 of 1

between square brackets inc. square brackets

Posted: Mon Aug 30, 2010 3:56 am
by Zugzwangle
hi, what would the regex be, to find all content between square bracket including the brackets themselves? for example I want to find and delete [color=blue:2cd68fd71f] and [/color:2cd68fd71f]

Re: between square brackets inc. square brackets

Posted: Mon Aug 30, 2010 5:17 am
by MichaelR

Code: Select all

'/\[[^\[\]]+\].+\[\/[^\[\]]+\]/'
This, perhaps?

Or if you want to distinguish between different things in between the brackets, you can be more specific like this, which works for the example you gave:

Code: Select all

'/\[color=[a-z]+:[a-f0-9]{10}\].+\[\/color=[a-z]+:[a-f0-9]{10}\]/i'

Re: between square brackets inc. square brackets

Posted: Mon Aug 30, 2010 5:17 am
by josh
(\[.*?\])

Micheal as far as I can tell he's not trying parse bbcode. He's trying to match the bbcode itself, not the text encapsulated within bb tags. Like a strip tags function made for removing unwanted bbcode formatting.

Re: between square brackets inc. square brackets

Posted: Mon Aug 30, 2010 5:22 am
by MichaelR
Ah, I see. My mistake.