### Question:
RegExPattern { public static void checkPatternConsistency (@Nonnull @RegEx final String sRegEx) { int nIndex = 0; while (nIndex >= 0) { nIndex = sRegEx.indexOf ('$', nIndex); if (nIndex != -1) { if (nIndex == sRegEx.length () - 1) { } else if (!Character.isDigit (sRegEx.charAt (nIndex + 1))) { if (nIndex + 1 < sRegEx.length () && sRegEx.charAt (nIndex + 1) == ')') { } else if (nIndex > 0 && sRegEx.charAt (nIndex - 1) == '\\') { } else throw new IllegalArgumentException ("The passed regex '" + sRegEx + "' contains an unquoted '$' sign at index " + nIndex + "!"); } nIndex++; } } } RegExPattern(@Nonnull @Nonempty @RegEx final String sRegEx);  RegExPattern(@Nonnull @Nonempty @RegEx final String sRegEx, @Nonnegative final int nOptions); static boolean areDebugConsistencyChecksEnabled(); static void enableDebugConsistencyChecks(final boolean bEnable); static void checkPatternConsistency(@Nonnull @RegEx final String sRegEx); @Nonnull @Nonempty @RegEx String getRegEx(); @Nonnegative int getOptions(); @Nonnull Pattern getAsPattern(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testCheckPatternConsistency () { RegExPattern.checkPatternConsistency ("any\\$here"); RegExPattern.checkPatternConsistency ("at the end$"); RegExPattern.checkPatternConsistency ("group $1 of $0"); RegExPattern.checkPatternConsistency ("$1 and $2 are OK"); try { RegExPattern.checkPatternConsistency ("any$here"); fail (); } catch (final IllegalArgumentException ex) {} }