I am creating a BBCODE CSS Parser which I am going to post for everyone to be able to use once finished. I have most of it ready to go except for one of the most important parts, the regular expressions and code to find and add or replace.

Here is a sample BBCode:

table{width:200px;height:40px;border:1px solid #DDD;background-color:#FFF;color:#000}
I need a function that will add an identifier before each left curly brace '{' and any information that is in front of it. Ultimately making the result look like this adding the identifier #id123:

<style type="text/css">
#id123 {background:url('images/background.jpg');color:#FFF;padding:5px}
#id123 table{width:200px;height:40px;border:1px solid #DDD;background-color:#FFF;color:#000}
#id123 .title{font-size:16px}
It also needs to check to make sure that < or > are not in between the left and right curly braces and if so, removes them and that only letters, numbers, #, and . exist before the left curly brace.

What this does is allows a user to use CSS in his posting but limits it to only his posts.

I know this is a tough one but someone has to know how.

Any help would be great. Thanks!