Java tutorial
//package com.java2s; /** * Appcelerator Titanium Mobile * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static final Pattern SIZED_VALUE = Pattern.compile("([0-9]*\\.?[0-9]+)\\W*(px|dp|dip|sp|sip|mm|pt|in)?"); public static float getSize(String size) { float value = 15.0f; if (size != null) { Matcher m = SIZED_VALUE.matcher(size.trim()); if (m.matches()) { value = Float.parseFloat(m.group(1)); } } return value; } }