List of usage examples for java.lang String matches
public boolean matches(String regex)
From source file:com.asual.summer.core.util.StringUtils.java
public static String ellipsis(String str, int length) { String space = " "; String ellipsis = "..."; length = length - ellipsis.length(); if (str.length() > length) { String[] words = str.substring(0, length).split(space); if (words.length > 1) { str = join(ArrayUtils.remove(words, words.length - 1), space); } else {/*from w w w . j ava2s . com*/ str = words[0]; } String end = str.substring(str.length() - 1, str.length()); if (end.matches("\\.|\\?|\\!|,")) { str = str.substring(0, str.length() - 1); } return str + ellipsis; } return str; }
From source file:com.github.devnied.emvnfccard.utils.AtrUtils.java
/** * Method used to find description from ATR * //from w ww. j a va 2s . c o m * @param pAtr * Card ATR * @return list of description */ @SuppressWarnings("unchecked") public static final Collection<String> getDescription(final String pAtr) { Collection<String> ret = null; if (StringUtils.isNotBlank(pAtr)) { String val = StringUtils.deleteWhitespace(pAtr); for (String key : MAP.keySet()) { if (val.matches("^" + key + "$")) { ret = (Collection<String>) MAP.get(key); break; } } } return ret; }
From source file:Main.java
public static boolean passwordz(String input1) { String patternStr = "^((?![a-zA-Z0-9]+$)(?![^a-zA-Z/D]+$)).{6,20}$|((?![^0-9/D]+$)(?![^a-zA-Z/D]+$)).{6,20}$|((?![a-zA-Z0-9]+$)(?![^0-9/D]+$)).{6,20}$"; Pattern pattern = Pattern.compile(patternStr); return input1.matches(patternStr); }
From source file:at.pcgamingfreaks.Version.java
/** * Checks if the given version string matches the required format. * * @param version The String to check.//from ww w. j ava 2 s .co m * @return True if the string matches the format. False if not. */ public static boolean isValidVersionString(String version) { return version.matches(VERSION_STING_FORMAT); }
From source file:ch.tkuhn.nanobrowser.NanopubElement.java
public static void deleteAllNanopubsWithProperty(String propertyURI) { if (propertyURI.matches("^[a-z]+://")) { propertyURI = "<" + propertyURI + ">"; }// ww w.jav a 2 s. c o m String query = getNanopubGraphsWithPropertyQuery.replaceAll("@P", propertyURI); for (BindingSet bs : TripleStoreAccess.getTuples(query)) { (new NanopubElement(bs.getValue("pub").stringValue())).delete(); } }
From source file:fr.gael.dhus.datastore.processing.impl.ProcessingUtils.java
static String checkPathElement(String elt) { if (elt.matches("(\\d.*)|(.*-.*)")) return "*[name()=\"" + elt.replaceAll("%20", " ") + "\"]"; else/*from w w w. j a v a 2s.c o m*/ return elt; }
From source file:Main.java
public static boolean isValidYearMonthDuration(String value) { // regex for checking valid xsd:yearMontheDuration string. See // http://www.schemacentral.com/sc/xsd/t-xsd_yearMonthDuration.html String regex = "-?P((\\d)+Y)?((\\d)+M)?"; return value.length() > 1 && value.matches(regex); }
From source file:com.cats.version.utils.Utils.java
public static String getLocalHostIp() { String regex = "[\\d]+.[\\d]+.[\\d]+.[\\d]+"; Enumeration<?> e = null; try {/*from w ww . j a v a2 s. c o m*/ e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); } while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration<?> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); String ip = i.getHostAddress(); if (ip.matches(regex) && !ip.equals("127.0.0.1")) { return ip; } } } return null; }
From source file:ste.web.http.beanshell.BeanShellUtils.java
public static void setup(final Interpreter interpreter, final HttpRequest request, final HttpResponse response, final HttpSessionContext context) throws EvalError, IOException { ////from w ww.j a v a 2 s. c om // Set attributes as script variables // for (String k : context.keySet()) { String key = normalizeVariableName(k); interpreter.set(key, context.getAttribute(k)); } // // If the request contains url-encoded body, set the given parameters // Header[] headers = request.getHeaders(HttpHeaders.CONTENT_TYPE); if (headers.length > 0) { String contentType = headers[0].getValue(); if (contentType.matches(ContentType.APPLICATION_FORM_URLENCODED.getMimeType() + "( *;.*)?")) { HttpEntityEnclosingRequest r = (HttpEntityEnclosingRequest) request; HttpEntity e = r.getEntity(); QueryString qs = QueryString.parse(IOUtils.toString(e.getContent())); for (String n : qs.getNames()) { String name = normalizeVariableName(n); interpreter.set(name, qs.getValues(n).get(0)); } } } // // Set request parameters as script variables. Note that parameters // override attributes (note that these override form content // try { QueryString qs = QueryString.parse(new URI(request.getRequestLine().getUri())); for (String n : qs.getNames()) { String name = normalizeVariableName(n); interpreter.set(name, qs.getValues(n).get(0)); } } catch (URISyntaxException x) { // // nothing to do // } BasicHttpConnection connection = (BasicHttpConnection) context .getAttribute(HttpCoreContext.HTTP_CONNECTION); interpreter.set(VAR_REQUEST, request); interpreter.set(VAR_RESPONSE, response); interpreter.set(VAR_SESSION, context); interpreter.set(VAR_OUT, connection.getWriter()); interpreter.set(VAR_LOG, log); if (HttpUtils.hasJSONBody(request) && (request instanceof HttpEntityEnclosingRequest)) { interpreter.set(VAR_BODY, getJSONBody(getEntityInputStream(request))); } }
From source file:framework.retrieval.engine.common.RetrievalUtil.java
/** * HTML?//from ww w . j a v a2 s . c o m * @param htmlContent * @param charsetName * @return */ public static String parseHTML(String htmlContent, String charsetName) { if (null == htmlContent || "".equals(htmlContent.trim())) { return htmlContent; } StringBuffer txt = new StringBuffer(); Pattern pattern = Pattern.compile("<[^<|^>]*>", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(htmlContent); while (matcher.find()) { String group = matcher.group(); if (group.matches("<[\\s]*>")) { matcher.appendReplacement(txt, group); } else { matcher.appendReplacement(txt, ""); } } matcher.appendTail(txt); String str = txt.toString(); return str; }