2

I'm trying to find blocks like these using regex. An example of the code I'm trying to find is shown bellow,

entity //This is what I want to select
{
    "id" "2"
    "classname" "light"   //This is what it should contain
    "_light" "255 255 255 200"
    "_lightHDR" "-1 -1 -1 1"
    "_lightscaleHDR" "1"
    "_quadratic_attn" "1"
    "origin" "-128 0 -128"
    editor
    {
        "color" "220 30 220"
        "visgroupshown" "1"
        "visgroupautoshown" "1"
        "logicalpos" "[0 0]"
    }
}

How would I go forward finding this block? Blocks not containing "classname" "light" should not be selected. Can anyone help me out?

1
  • is it classname fix and light variable ? Commented Dec 8, 2013 at 5:10

1 Answer 1

4

Try this:

entity\s*\{[^}]*"classname" "light"[^}]*\}\s*\}

The key term here is [^}]*, which ensures the match doesn't run over to the next block.

See a live demo of this regex in action with your example and a non-matching example.

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

3 Comments

Exactly what I was looking for! Thank you so much! Regex is pretty confusing if you don't have experience with it.
@mats it's worth learning. You would be surprised how many occasions you can use it and save yourself lots of code.
I know this is a very late reply, but I just wanted to thank you for encouraging me to learn regex. It has helped so much since I posted this. Thank you!

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.