views:

45

answers:

2

Hi There

I am hoping that someone can help me with this regex, I need to grab test2 and everything between { }

    .test1 {font-family: Arial, Helvetica, sans-serif; color: #42bf32; font-size: 14px; }
.test2 {font-family: Arial, Helvetica, sans-serif; color: #42bf32; font-size: 14px; }
.test3 {font-family: Arial, Helvetica, sans-serif; color: #42bf32; font-size: 14px; }

I am using ASP and Javascript

I have a feeling the regex would be something like this test2.replace(/\.test(.*?)\{(.*?)\}/ig, '.test3');

Any help would be appreciated

Thanks to Steward it now works fine .replace(/.test *{[^}]*/ig, '');

+2  A: 
test2[[:space:]]*{[^}]*}

But you should probably use a real css parser instead.

Stuart
Thanks Stuart i have chaged ut to .replace(/.test *{[^}]*/ig, ''); but it leaves the last } in the code. any idea why?
Gerald Ferreira
lol wait I think I see what I have done wrong .replace(/.test *{[^}]*}/ig, ''); let me try it like this
Gerald Ferreira
You can format your code by indenting it with 4 spaces (look at the box to the right when editing an answer).
Marcel Korpel
No CSS comments like `.test2 { font-family: Arial /* }{ */ }` ?
Wrikken
hi Wrikken nice idea to include comments :-) I have not comments in my styles - I am building an online css editor - with basic functionality...
Gerald Ferreira
+1  A: 
/\.test2\s*\{.*\}/

You also might want to look into other RegExp methods, replace may not be what you want. Specifically, you should check out test() and exec(). See Javascript Kit's Regex Tutorial.

vol7ron