-10

I have some code:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;

private boolean validateEmail(...)

Pattern p = Pattern.compile("^((?:(?:(?:[a-zA-Z0-9][\\.\\-\\+_]?)*)[a-zA-Z0-9])+)\\@((?:(?:(?:[a-zA-Z0-9][\\.\\-_]?){0,62})[a-zA-Z0-9])+)\\.([a-zA-Z0-9]{2,6})$");

Matcher m = p.matcher(fieldValue);
boolean matches = m.matches();

if (!matches) {    
// show not valid msg...
}
return matches;
}

What do ^((?:(?:(?: and ((?:(?:(?: mean in that pattern? The ^ character mean negation (all without) but other characters?

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
bischop
  • 19
  • 1
  • 4
  • 4
    What does [the documentation](http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html) tell you they mean? – T.J. Crowder Oct 22 '13 at 08:56
  • Here are couple java regex tutorial to get u started with : http://www.vogella.com/articles/JavaRegularExpressions/article.html http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html – codeMan Oct 22 '13 at 08:57
  • 10
    They are smiles - this is the way how regex shows it's sympathy to you. – Alma Do Oct 22 '13 at 08:58
  • More explicitly, they are sarcastic smiles. – Seshadri R Aug 25 '18 at 05:53

1 Answers1

3

(?:...) denotes a non capturing group. ?: is used when you want to group an expression, but you want to avoid to return it as a matched/captured portion of the string.

The ^ does not mean negation when it is located outside square breackets. It means match from the beginning of the string.

user278064
  • 9,982
  • 1
  • 33
  • 46