List of usage examples for java.util.regex Matcher matches
public boolean matches()
From source file:Main.java
/** * Returns true if the given string is an email. *///w ww.j a va 2 s . co m private static boolean isEmail(String account) { if (TextUtils.isEmpty(account)) { return false; } final Pattern emailPattern = Patterns.EMAIL_ADDRESS; final Matcher matcher = emailPattern.matcher(account); return matcher.matches(); }
From source file:com.changhong.app.utils.ValidatorUtils.java
public static boolean isNumeric(String str) { if (str == null) return false; String trimedStr = org.springframework.util.StringUtils.trimAllWhitespace(str); if (trimedStr.length() == 0) return false; Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(trimedStr); return isNum.matches(); }
From source file:edu.infsci2560.LoginHelper.java
private static HttpHeaders getHeaders(TestRestTemplate template, String route) { // todo : write getHeaders test HttpHeaders headers = new HttpHeaders(); ResponseEntity<String> page = template.getForEntity(route, String.class); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); String cookie = page.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); Matcher matcher = pattern.matcher(page.getBody()); assertThat(matcher.matches()).as(page.getBody()).isTrue(); headers.set("X-CSRF-TOKEN", matcher.group(1)); return headers; }
From source file:Main.java
public static CharSequence[] splitCoordsAndDescription(CharSequence location) { Matcher matcher = PAT_ATSIGN_FORMAT.matcher(location); if (matcher.matches()) { return new CharSequence[] { matcher.group(2).trim(), matcher.group(1).trim() }; }/*from w w w. j a v a 2 s. c om*/ matcher = PAT_PAREN_FORMAT.matcher(location); if (matcher.matches()) { return new CharSequence[] { matcher.group(1).trim(), matcher.group(2).trim() }; } // No description. return new CharSequence[] { location, "" }; }
From source file:Main.java
public static boolean isNumericalVersion(String version) { Pattern numVersionPattern = Pattern.compile(numericalVersionRegex); Matcher matcher = numVersionPattern.matcher(version); return matcher.matches(); }
From source file:Main.java
public static boolean EmailValidation(EditText email) { String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; Pattern pattern = Pattern.compile(EMAIL_PATTERN); Matcher matcher; matcher = pattern.matcher(email.getText().toString()); return matcher.matches(); }
From source file:Main.java
/** * Helper function for decode XML entities. * * @param str The XML-encoded String to decode. * @return An XML-decoded String.//from w ww . jav a2s. c om */ public static String decode(String str) { if (str == null) { return null; } Matcher gtmatcher = encgt.matcher(str); if (gtmatcher.matches()) { str = gtmatcher.replaceAll(">"); } Matcher ltmatcher = enclt.matcher(str); if (ltmatcher.matches()) { str = ltmatcher.replaceAll("<"); } Matcher quotMatcher = encQuot.matcher(str); if (quotMatcher.matches()) { str = quotMatcher.replaceAll("\""); } Matcher ampMatcher = encAmp.matcher(str); if (ampMatcher.matches()) { str = ampMatcher.replaceAll("&"); } return str; }
From source file:net.jadler.stubbing.server.jdk.RequestUtils.java
static void addEncoding(final Request.Builder builder, final HttpExchange httpExchange) { final String contentType = httpExchange.getRequestHeaders().getFirst("Content-Type"); if (contentType != null) { final Matcher matcher = CHARSET_PATTERN.matcher(contentType); if (matcher.matches()) { try { builder.encoding(Charset.forName(matcher.group(1))); } catch (UnsupportedCharsetException e) { //just ignore, fallback encoding will be used instead }// w w w . j ava 2 s . c o m } } }
From source file:com.ignorelist.kassandra.steam.scraper.LibraryScanner.java
public static Set<Long> findGames(Path path) throws IOException { Set<Long> gameIds = new HashSet<>(); DirectoryStream<Path> directoryStream = null; try {//w ww .j a v a 2 s.co m directoryStream = Files.newDirectoryStream(path, new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return Files.isRegularFile(entry); } }); for (Path f : directoryStream) { final String fileName = f.getFileName().toString(); Matcher matcher = PATTERN.matcher(fileName); if (matcher.matches()) { gameIds.add(Long.parseLong(matcher.group(1))); } } return gameIds; } finally { IOUtils.closeQuietly(directoryStream); } }
From source file:com.mastfrog.acteur.util.BasicCredentials.java
public static BasicCredentials parse(String header) { Matcher m = HEADER.matcher(header); if (m.matches()) { String base64 = m.group(1); // byte[] decoded = Base64.getDecoder().decode(base64); // String s = new String(decoded, UTF_8); byte[] bytes = base64.getBytes(UTF_8); if (Base64.isArrayByteBase64(bytes)) { bytes = Base64.decodeBase64(bytes); }/*from ww w . j ava 2 s. c o m*/ String s = new String(bytes, US_ASCII); m = UNPW.matcher(s); if (m.matches()) { String username = m.group(1); String password = m.group(2); return new BasicCredentials(username, password); } } return null; }