I need a regular expression which would do the following –>
For example,
margin:7px 7px 7px 7px;
Should be compressed to –>
margin:7px;
(NOTE: The number may not be only 7,it can be any number. And the units can be in px|em|%|in|cm|mm|pc|pt|ex)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is definitely possible in the specific case of being repeated 4 times.
Using backreferences, this is possible for a particular value of
nthe number of times the number is repeated. In your case,n = 4.This one matches any “unit” value made up of only alpha characters, i.e. “px”, “em” or “foo”, plus the special case “%”. It could be made more restrictive to particular units by replacing
\w*with a more specific match like(?:em|px|......)For example: