Blog Archive for September 27, 2010

RegEx in Java

September 27, 2010

Here's a snippet of Java code for validating an entire string aginst a regex:

boolean lValid = pValue.matches("[A-Za-z0-9_\\.\\-]+@[A-Za-z0-9\\.\\-]+\\.[A-Za-z\\.]+");

In this case we're validating that the string contains an email address. Note that this function implicitly adds a ^ at the start of the regex and …

Tags: java regex