Regular expression which matches a pattern, or is an empty string
I have the following Regular Expression which matches an email address format: ^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$ This is used for validation with a form using JavaScript. However, this is an optional field. Therefore how can I change this regex to match an email address format, or an empty string? From my limited regex knowledge, I think \b matches an empty string, and | means "Or", so I tried to do the following, but it didn't work: ^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$|\b polygenelubricants To match pattern or an empty string, use ^$|pattern Explanation ^ and $ are the beginning and end of the