jquery - Javascript regular expression matching css selectors -


i'm trying match regular expression against set of css rules. part of code not working:

selector = $.trim(selector.replace('.', '\.')); var re = new regexp('/'+selector+'(?=\{| \{|   \{)/', 'g'); 

here i'm escaping fullstop in selector in case class eg ".styler".

then i'm trying match specific selector followed curly bracket or 1 space , curly bracket, or 2 spaces , curly bracket.

what i'm trying achieve is
selector ".styler" matches: ".styler{" , ".styler {", ".styler {"
, not match: ".styler span{", ".styler h1 {" etc.

backslash escapes next character in js string. need escape backslash too:

selector = $.trim(selector.replace('.', '\\.')); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -