1

I have this CSS block:

@component HelloWorld {
  background-color: red;
  padding: 1rem;

  @modifier red {
    color: green;
  }
}

and I want to find all the contents in this block until the blocks end (with })

I wrote the following regex and I don't know how to ignore all of the brackets inside the block and find only the closing one.

[\s]{0,}@([\w]+)[ ]{1,}([\w\d]+)[ ]{0,}{.+?(?=})

example

and also I want to match all of the blocks if I have the following CSS:

@modifier red {
  color: green;
}

@modifier red {
  color: green;
}
11
  • .+} will match everything before } Commented Oct 1, 2018 at 7:48
  • @VaibhavVishal, please look at this example: regex101.com/r/WrGWZo/2, i want to match two of the blocks Commented Oct 1, 2018 at 7:50
  • try this .+?} Commented Oct 1, 2018 at 7:51
  • @VaibhavVishal, and now I have a problem with the first example, I edited the question with more information. I hope my question is understandable Commented Oct 1, 2018 at 7:53
  • You need [^}]*, \s*@(\w+)\s+(\w+)\s*{[^}]+}, see regex101.com/r/WrGWZo/3 Commented Oct 1, 2018 at 7:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.