Showing posts with the label Regex

Java Regular Expression - Username, Password, Email, IPAddress Example

Package java.util.regex   A regex is used as a search pattern for strings. We can look for any kind of match in a string e.g. a simple character, a fixed string or any complex pattern of characters such as password, email, IPAddress, username, pin etc... For Example, Username Regular Expression: ^[a-zA-Z0-9._-]{3,}$ Password Regular Expression: ((?=.*[a-z])(?=.*\\d)(?=.*[A-Z])(?=.*[@#$%!]).{8,40}) Email Regular Expression: ^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$ IP address Regular Expression: ^((0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)\\.){3}(0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)$ Java Regular Expression Example: Validator Class import java.util.regex.Matcher; import java.util.regex.Pattern; public class Validator { private static Pattern pattern; private static Matcher matcher; private static final String PASSWORD_PATTERN =