0

I've got a string that I have to match and extract a css class name out of it. The string:

.c.-my-text-overlay-second

the class I have to match has to contain text-overlay inside or at the end of the class name. So in this case, what I want to extract is .-my-text-overlay-second.

I have tried multiple things, but I either get the .c:

(.*\..*?text-overlay.*)

or I get only text-overlay:

.*(\..*?media-overlay-active)

What should be the correct expression?

2
  • Maybe you are tying to do it this way \.[\w-]*text-overlay[\w-]* Commented Jun 23, 2017 at 14:22
  • 1
    @revo this is correct. Great regex work! The link is useful, I will be able to understand how the hell it works :) Commented Jun 23, 2017 at 14:26

1 Answer 1

1

You shouldn't use a greedy dot .* in your Regular Expression since it will match everything from beginning to the point the next pattern (if exists) matches. That's the reason of matching whole input string while text-overlay exists in it.

Your regex should begin with a dot and the rest should correspond to class naming rules:

\.[\w-]*text-overlay[\w-]*
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.