question: private String checkforRegex ( String aRegexFragment ) { final StringBuilder result = new StringBuilder ( ) ; final StringCharacterIterator iterator = new StringCharacterIterator ( aRegexFragment ) ; char character = iterator . current ( ) ; while ( character != CharacterIterator . DONE ) { if ( character == '.' ) { result . append ( "\\." ) ; } else if ( character == '\\' ) { result . append ( "\\\\" ) ; } else if ( character == '?' ) { result . append ( "\\?" ) ; } else if ( character == '*' ) { result . append ( "\\*" ) ; } else if ( character == '+' ) { result . append ( "\\+" ) ; } else if ( character == '&' ) { result . append ( "\\&" ) ; } else if ( character == ':' ) { result . append ( "\\:" ) ; } else if ( character == '{' ) { result . append ( "\\{" ) ; } else if ( character == '}' ) { result . append ( "\\}" ) ; } else if ( character == '[' ) { result . append ( "\\[" ) ; } else if ( character == ']' ) { result . append ( "\\]" ) ; } else if ( character == '(' ) { result . append ( "\\(" ) ; } else if ( character == ')' ) { result . append ( "\\)" ) ; } else if ( character == '^' ) { result . append ( "\\^" ) ; } else if ( character == '$' ) { result . append ( "\\$" ) ; } else if ( character == '|' ) { result . append ( "\\|" ) ; } else { result . append ( character ) ; } character = iterator . next ( ) ; } return result . toString ( ) ; }
target:  Replace characters having special meaning in regular expressions