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