I'm currently working on creating a regex pattern to identify all ID selectors within a CSS file. Essentially, I am looking for any word that begins with a # symbol.
#\w+
However, there is a complication as color values can also start with a #. Therefore, my goal is to locate words starting with a # that are NOT enclosed between { and } brackets. Unfortunately, I'm struggling to formulate this in the correct syntax.
I am using Notepad++ so I require a regex expression compatible with that platform.
For context, my ultimate objective is to remove everything from the file that is not an ID selector, resulting in a clean list of selectors. Initially, I attempted:
Find: [^#]*(#\w+)
Replace: \1\r\n
... then executed Replace All function.
However, I encountered the issue related to colors.
Update
Someone requested for an example. Here's one:
Input:
.foo {max-width: 500px;}
#bar {text-align: left;}
.splunge, #plugh {color: #ff0088;}
Desired output:
#bar
#plugh
The key point is to include only the "pound strings" outside of braces, excluding those inside braces.