java regex pattern validate username

Regular expression username pattern ^[a-z0-9_-]{5,15}$^[a-z0-9_-]{5,15}$ This regular expression refers to a pattern which accepts 5 to 15 characters with any lower case character, digit or special symbol “_-” only. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "^[a-z0-9_-]{5,15}$"; public static … Read more

Java regex validate alphabets

Regular expression to accept only alphabets [a-zA-Z]+\.?[a-zA-Z]+\.? This regular expression refers to a pattern which accepts alphabets only. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "[a-zA-Z]+\.?"; public static void main(String args[]){ List<String> values = new ArrayList<String>(); values.add("Jai"); values.add("Jai5"); values.add("12345"); … Read more

Java regex validate number

Regular expression to accept only digits \d+$\d+$ This regular expression refers to a pattern which accepts only digits. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "\d+$"; public static void main(String args[]){ List<String> values = new ArrayList<String>(); values.add("Jai"); values.add("12345345"); values.add("1234567890"); … Read more

Java regex validate 10 digit number

Regular expression to accept 10 digit number \d{10}\d{10} This regular expression refers to a pattern which accepts 10 digits number only. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "\d{10}"; public static void main(String args[]){ List<String> values = new ArrayList<String>(); … Read more

java regex validate alphanumeric

Regular expression to accept alphanumeric only ^[a-zA-Z0-9]+$^[a-zA-Z0-9]+$ This regular expression refers to a pattern which accepts all lower and upper case characters, and digits only. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "^[a-zA-Z0-9]+$"; public static void main(String args[]){ List<String> … Read more

Java regular expression metacharacters

Java regex metacharacters Regex Description . Any character (may or may not match terminator) d Any digits, short of [0-9] D Any non-digit, short for [^0-9] s Any whitespace character, short for [tnx0Bfr] S Any non-whitespace character, short for [^s] w Any word character, short for [a-zA-Z_0-9] W Any non-word character, short for [^w] b … Read more

Java Regex Quantifiers

Java Regex Quantifiers The quantifiers specify how often an element can occur. The symbols ?, *, + and {} define the quantity of the regular expressions.   Regex Description X? X occurs once or not at all X+ X occurs once or more times X* X occurs zero or more times X{n} X occurs n … Read more

Java regular expression character class regex

Java Regex Character classes Character Class Description [abc] a, b, or c (simple class) [^abc] Any character except a, b, or c (negation) [a-zA-Z] a through z or A through Z, inclusive (range) [a-d[m-p]] a through d, or m through p: [a-dm-p] (union) [a-z&&[def]] d, e, or f (intersection) [a-z&&[^bc]] a through z, except for … Read more

Java Regular expressions regex tutorial

Regular expressions Regular expressions represent a sequence of symbols and characters expressing a string or pattern to be searched for within a longer piece of text. The abbreviation for regular expression is regex. In programming regular expressions are mainly used to define constraints on strings like passwords, and email validation. The java.util.regex package primarily consists … Read more