0

I have the following CSS div / class mark-up

.myclass #myid{
    width: ;
    height: ;
}

This is in about a dozen CSS files. Each CSS file has different widths and heights defined. I'd like to replace all of the markup in each file with a single consistent mark-up. Something like this

.myclass #myid{
    width: 20px;
    height: 30px;
}

Is this possible with PHPStorm?

1 Answer 1

2

Yes -- it's possible to find such exact matches (specific selector that has "width" and "height" properties defined in that order). You just need some rather basic knowledge of regular expressions.

  1. Use "Replace In Path" dialog (Edit | Find | Replace in Path Ctrl+Shift+R)
  2. Activate "Regular Expression" option
  3. Set correct scope (Whole Project or specific scope/folder/etc)
  4. Type your regular expressions:
    • Text to find: (\.myclass \#myid\s*\{\n\s*width:\s*)\d+(px;\n\s*height:\s*)\d+(px;)
    • Replace with: $122$233$3
  5. Hit the button

NOTES:

  • The regex for "replace with" will set "width" to 22 and "height" to 33 -- edit them as required.
  • Same with "text to find" regex -- the one which I write will not find if you write something like width: 0; ("px" unit is omitted). I've built it based on your example, so if it differs you will have to adjust it yourself.
  • That regex will not work if you have any other property before "width" .. or in different order.

enter image description here

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.