I have the following CSS code:
#np-toolbar-l a{ position: relative; padding: 0px 8px; line-height: 30px; display: inline-block; font-size: 12px; }
#np-toolbar-l a:hover{ background-color: #EFEFEF; opacity: 0.7; }
#np-toolbar-l a *:hover{ cursor: pointer; }
/** Icon */
#np-toolbar [class^="icon-"]{ font-size: 18px; vertical-align: middle; margin-right: 5px; }
I am trying to replace np-toolbar
to another ID,
I just want to match np-toolbar
not np-toolbar-l
or something like this,
here's a tutoral about how to capture all the IDs from CSS:
#-?[_a-zA-Z]+[_a-zA-Z0-9-]*(?=[^}]*\{)
source: Regex to match ids in a css file?
I couldn't find out how do I search a "compelete ID" by regex,
here's my example: (It'll still count np-toolbar-l
in)
/(?<=(#|\.))(np-toolbar)+(?=( |:||\[))/
EDIT: ummm, jsut added some symbols behind it,
it looks like the answer which I am looking for
/(?<=(#|\.))(np-toolbar)+(?=( |:|\[|\{|\.|,))/
If you're looking for a specific ID, you can greatly simplify your regex:
/(#np-toolbar)(?=[{.,\s])/g
That should find the ID wherever it appears in the CSS. It first matches the ID exactly, then only allows {
(for beginning the style), ,
(for listing selectors), .
(for appended classes), or space/tab/newline characters afterwards, preventing it from matching IDs like np-toolbar-1
etc.
Maybe you could try this regexp:
/#np-toolbar(?![-\w])/
which means: match all "#np-toolbar" inclusions if inclusion doesn't end with "-" or any \w symbol