I am attempting to extract a element's id from a selector. For example if I have the following selector body .foo #bar
I wish to extract the #bar
text. And for #foo:hover
I wish to extract #foo
. I have created a regular expression that works for all cases except for selectors that contain :
, so it doesn't work for my last example #foo:hover
. It seems to be greedy and grabs all text #foo:hover
instead of just #foo
See here for an example of my issue: https://regex101.com/r/7Rk6AL/2
Can you suggest how I edit my regex to achieve my goal of just getting the selector id and not the :hover
part?