I’m writing a regexp in Java where I’m trying to find the bottom-margin in the css “margin:” shorthand property in a String and see if it’s negative.
The margin property can be specified with 1, 2, 3 or 4 values, end with px, em or % and the values might be negative and/or start with a dot. Values are separated with one or more white spaces in between. What is tried so far is a regexp like this:
//E.g. style may look like "... margin: 10px 2px" or "... margin: -.10em 1em 2em" etc.
public void findMargin(String style)
{
Pattern compile = Pattern.compile("margin:\\s*(-?\\.?\\d+(?:em|px|%)\\s*){1,4}");
Matcher matcher = compile.matcher(style);
while (matcher.find())
{
.....
}
}
I have problem to find the extract the bottom-margin property. Anyone have some input on how to achieve that?
This is the code I wrote to find the bottom-margin from the css margin shorthand property: