0

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, '');

1
  • 2
    why are you trying to grab the css w/ regex? there's probably a better solution to what you're doing, then to use regex. Commented Jul 23, 2010 at 23:21

2 Answers 2

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

But you should probably use a real css parser instead.

Sign up to request clarification or add additional context in comments.

5 Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.