What should be the valid characters in usernames? [closed]

A well-designed system doesn’t necessarily need to prevent any special characters in usernames. That said, the reason underscores have traditionally been accepted, is that underscore is typically treated as a “word” character, along with letters and numbers. It is usually the only other character given this distinction. This is true in regular expressions, and even … Read more

Escaping special character when generating an XML in Java

You can use apache common lang library to escape a string. org.apache.commons.lang.StringEscapeUtils String escapedXml = StringEscapeUtils.escapeXml(“the data might contain & or ! or % or ‘ or # etc”); But what you are looking for is a way to convert any string into a valid XML tag name. For ASCII characters, XML tag name must … Read more

String.split() at a meta character +

replaceAll accepts a regular expression as its first argument. + is a special character which denotes a quantifier meaning one or more occurrences. Therefore it should be escaped to specify the literal character +: rightside = rightside.replaceAll(“\\+”, ” +”); (Strings are immutable so it is necessary to assign the variable to the result of replaceAll); … Read more