Posts

Showing posts with the label regular expression

Java Regular Expressions parameters example

Java Regular Expressions parameters example characters . Any character (may or may not match line terminators) \d A digit: [0-9] \D A non-digit: [^0-9] \s A whitespace character: [ \t\n\x0B\f\r] \S A non-whitespace character: [^\s] \w A word character: [a-zA-Z_0-9] \W A non-word character: [^\w] Match: \d matches all digits \s matches spaces \w matches word characters Alternatively, a capital letter means the opposite: \D matches non-digits \S matches non-spaces \W matches non-word characters Boundary Construct Description ^ The beginning of a line $ The end of a line \b A word boundary \B A non-word boundary \A The beginning of the input \G The end of the previous match \Z The end of the input but for the final terminator, if any \z The end of the input Example: private final String REGEX = "\\d"; // a single digit Pattern p = Pattern.compile(REGEX);        //  get a matcher object   ...

Website URL name regular expression validator

Java Best Website URL name regular expression validator public class Utility { public static boolean isValidURL(String url)   { String urlPattern = "^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*";     if (url.matches(urlPattern))       return true;     else return false;   } }

java restful web services @path regular expression

1          The following example shows how regular expression could be used with the @Path annotation.        @Path("users/{username: regular expression}")          Example:         @Path("users/{username: [a-zA-Z][a-zA-Z_0-9]}")         following URL:   http://example.com/users/hello 2                  The @PathParam annotation example         @Path("/users/{username}")         public class User {         @GET          @Produces("text/xml")          public String getUser(@PathParam("username") String              userName) {         System.out.println(userName);         }         }