OVERVIEW
Short for regular expression, a regex is a string of text that allows you to create patterns that help match, locate, and manage text. You will find the list below very useful if you are building an online form or application.
List of useful RegEx
Type | RegEx | Remarks |
---|---|---|
Alphanumeric with space | ^[a-zA-Z0-9 ]*$ | |
Date (yyyy-MM-dd) | ^([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))$ | |
Email address | ^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$ | |
NRIC (xxxxxx-xx-xxxx) | ^(\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01]))\-(\d{2})\-(\d{4})$ | |
Numeric | ^-?[0-9]\d*(\.\d+)?$ | |
URL | ^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$ | |
URL | ^(https?:\/\/){1}(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$ | Does not accept email address as URL |