Good code red in 8.1.3

I got this regular expression code from a very helpful Sun web page. It
works but 8.1.3's error checking is barfing all over it:

static final String Digits = "(
p+)";
static final String HexDigits = "(
p+)";
// an exponent is 'e' or 'E' followed by an optionally
// signed decimal integer.
static final String Exp = "[eE][-]?"Digits;
static final String fpRegex =
("[+-]?(" + // Optional sign character
"NaN|" + // "NaN" string
"Infinity|" + // "Infinity" string

// A decimal floating-point string representing a finite positive
// number without a leading sign has at most five basic pieces:
// Digits . Digits ExponentPart FloatTypeSuffix
//
// Since this method allows integer-only strings as input
// in addition to strings of floating-point literals, the
// two sub-patterns below are simplifications of the grammar
// productions from the Java Language Specification, 2nd
// edition, section 3.10.2.

// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
"((("Digits"(
.)?("Digits"?)("Exp")?)|"+

// . Digits ExponentPart_opt FloatTypeSuffix_opt
"(
.("Digits")("Exp")?)|"+

// Hexadecimal strings
"((" +
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
"(0[xX]" + HexDigits + "(
.)?)|" +

// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
"(0[xX]" + HexDigits + "?(
.)" + HexDigits + ")" +

")[pP][+-]?" + Digits + "))" +
"[fFdD]?))" +
"[
x00-
x20]*");// Optional trailing "whitespace"
static final Pattern p = Pattern.compile(fpRegex);

Please sign in to leave a comment.