var s = "[name1=xxxx]yyyy[/name1]"; var re = /\[name1=([^\]]+)\]([^\[]*)\[\/name1\]/; var res = s.match(re); alert( res[1] ); alert( res[2] );