1

I'm trying to write a regex to extract nodes ids and classes from css selectorText.

For example:

.linear *, .test-in *, .test-out *, .test *, .test-in-out.casanova#casanova * > #test22

I need a regex to extract only the classes and ids:

linear , test-in , test-out , test , test-in-out , casanova , casanova , test22

so I need a regex to match any string that starts with ./# and ends with space/./# the first occurrence for any of them.

I manage to create this:

(?:^|[\.]).*?([^\s]+(?!\.))

but as you can see it doesn't work properly.

1 Answer 1

1
(?:\.|\#)([_a-zA-Z0-9-\:]*)(?:\b|<|>|\+|~|\[)

This regex will also capture some invalid css selectors such as -_--__abc. But in your case I believe this will solve your problem.

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

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.