1

I have the following two selectors in my css, laid out with this formatting:

// file1.css
#myId {
    margin-right:0;
    color:#f00;
}

// file2.css
#otherId { margin-right:0; color: #f00 }

My goal is to obtain the selector and the color value using a ack/grep search.

if I:

ack-grep '(^.*color:\s+\d+)'

I'll get:

file1.css
color:#f00;

file2.css
#otherId { margin-right:0; color: #f00 }

This search worked fine for file2.css, but not so well for file1.css, probably because I use ^ to match to the beginning of a line.. how would I consistently match back to the beginning of some css selector (starting with either an id or a class or tagname)?

to be more obvious, I want:

file1.css
#myId {margin-right:0; color:#f00;

file2.css
#otherId { margin-right:0; color: #f00 }

(and the selector doesn't necessarily have to be an ID.. should I match back to previous } or beginning of file?

1

1 Answer 1

2

Neither grep nor ack supports multi-line regexes:

ack FAQ

There are other alternatives, like pcregrep. I would use some CSS parser though.

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.