*/
RegExp mimicLookbehind = RegExp.compile("([\\\\]*)([?*])", "g");
StringBuilder wildcardStr = new StringBuilder(escaped);
for (MatchResult match = mimicLookbehind.exec(wildcardStr.toString()); match != null;
match = mimicLookbehind.exec(wildcardStr.toString())) {
// in some browsers an optional group is null, in others its empty string
if (match.getGroup(1) != null && !match.getGroup(1).isEmpty()) {
// We undo double-escaping of backslashes performed by the naive escape
int offset = match.getGroup(1).length() / 2;
wildcardStr.delete(match.getIndex(), match.getIndex() + offset);