I hope regex can help in finding the inefficient written values in the CSS. For example, some older developers write margin values as margins: 5px 5px 5px 5px , which I want to write in the shortcode as margin: 5 pix I am Obviously the number values (as well as unit values: Px, M,%, etc.) can vary, but I have to prepare a way to find those repeating numbers which all match each other.
Is this possible? Regex's my knowledge, sorry, is very limited. Does any kind person give me some indication that how will I achieve this method?
Thank you,
You must use "back reference" of regexp Example:
/ (padding | margin) [:] ([0-9] (px | em)) \ 2 \ 2 \ 2; You can do something like: $ your_css = preg_replace ('@ (padding | margin)] /
:] ([0-9] + (px | em)) \ s \ 2 \ s \ 2 \ s \ 2 \ s ?; @ Ui, '\ 1: \ 2;', $ your_css);
Comments
Post a Comment