Say you have a long regex, like the one for RFC5322 (email address). It is basically just a one-line-assignment operation to compile that monster, but it feels like that line is over nine thousand characters long. How would you line-wrap such a regex? Would you even care to wrap it?
// RFC5322
// regex taken from regular-expressions.info/email.html
Pattern cachedEmailRFCChecker = Pattern.compile("^\\A(?=[a-z0-9@.!#$%&'*+\\/=?^_`\\{|\\}~-]{6,254}\\z)(?=[a-z0-9.!#$%&'*+\\/=?^_`\\{|\\}~-]{1,64}@)[a-z0-9!#$%&'*+\\/=?^_`\\{|\\}~-]+(?:\\.[a-z0-9!#$%&'*+\\/=?^_`\\{|\\}~-]+)*@(?:(?=[a-z0-9-]{1,63}\\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+(?=[a-z0-9-]{1,63}\\z)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\z$");
I'd probs split it up into smaller, reusable sections that can individually be managed.
I personally wouldn't. Regex has its place, but if it takes over 20 characters to describe its purpose, then there must be a better solution.
Looks like you are using Java, so the Apache Commons Validator library should help out. It can validate emails and your could make it so that it doesn't use IP addresses or localhost as valid emails.
If you still feel this is best, then I would wrap it at matching parentheses, because those specify groups. Also at square brackets if necessary. If there is a plus or star at the end of either of them, I would put the new line after that, because those specify whether you want it to repeat. Same thing for curly brackets.
Pattern cachedEmailRFCChecker = Pattern.compile( "^\\A(?=[a-z0-9@.!#$%&'*+\\/=?^_`\\{|\\}~-]{6,254}\\z)" + "(?=[a-z0-9.!#$%&'*+\\/=?^_`\\{|\\}~-]{1,64}@)" + "[a-z0-9!#$%&'*+\\/=?^_`\\{|\\}~-]+" + "(?:\\.[a-z0-9!#$%&'*+\\/=?^_`\\{|\\}~-]+)* + "@(?:(?=[a-z0-9-]{1,63}\\.)" + "[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+" + "(?=[a-z0-9-]{1,63}\\z)[a-z0-9]" + "(?:[a-z0-9-]*[a-z0-9])?\\z$" );