docs: protected String replaceXPathPatterns( String expression ) {
          assert expression != null;
          // replace 2 or more sequential '|' characters in an OR expression
          expression = expression.replaceAll("[\\|]{2,}", "|");
          // if there is an empty expression in an OR expression, make the whole segment optional ...
          // (e.g., "/a/b/(c|)/d" => "a/b(/(c))?/d"
          expression = expression.replaceAll("/(\\([^|]+)(\\|){2,}([^)]+\\))", "(/$1$2$3)?");
          expression = expression.replaceAll("/\\(\\|+([^)]+)\\)", "(?:/($1))?");
          expression = expression.replaceAll("/\\((([^|]+)(\\|[^|]+)*)\\|+\\)", "(?:/($1))?");
  
          // // Allow any path (that doesn't contain an explicit counter) to contain a counter,
          // // done by replacing any '/' or '|' that isn't preceded by ']' or '*' or '/' or '(' with '(\[\d+\])?/'...
          // input = input.replaceAll("(?<=[^\\]\\*/(])([/|])", "(?:\\\\[\\\\d+\\\\])?$1");
  
          // Does the path contain any '[]' or '[*]' or '[0]' or '[n]' (where n is any positive integers)...
          // '[*]/' => '(\[\d+\])?/'
          expression = expression.replaceAll("\\[\\]", "(?:\\\\[\\\\d+\\\\])?"); // index is optional
          // '[]/' => '(\[\d+\])?/'
          expression = expression.replaceAll("\\[[*]\\]", "(?:\\\\[\\\\d+\\\\])?"); // index is optional
          // '[0]/' => '(\[0\])?/'
          expression = expression.replaceAll("\\[0\\]", "(?:\\\\[0\\\\])?"); // index is optional
          // '[n]/' => '\[n\]/'
          expression = expression.replaceAll("\\[([1-9]\\d*)\\]", "\\\\[$1\\\\]"); // index is required
  
          // Change any other end predicates to not be wrapped by braces but to begin with a slash ...
          // ...'[x]' => ...'/x'
          expression = expression.replaceAll("(?<!\\\\)\\[([^\\]]*)\\]$", "/$1");
  
          // Replace all '[n,m,o,p]' type sequences with '[(n|m|o|p)]'
          java.util.regex.Matcher matcher = SEQUENCE_PATTERN.matcher(expression);
          // CHECKSTYLE IGNORE check FOR NEXT 1 LINES
          StringBuffer sb = new StringBuffer();
          boolean result = matcher.find();
          if (result) {
              do {
                  String sequenceStr = matcher.group(1);
                  boolean optional = false;
                  if (sequenceStr.startsWith("0,")) {
                      sequenceStr = sequenceStr.replaceFirst("^0,", "");
                      optional = true;
                  }
                  if (sequenceStr.endsWith(",0")) {
                      sequenceStr = sequenceStr.replaceFirst(",0$", "");
                      optional = true;
                  }
                  if (sequenceStr.contains(",0,")) {
                      sequenceStr = sequenceStr.replaceAll(",0,", ",");
                      optional = true;
                  }
                  sequenceStr = sequenceStr.replaceAll(",", "|");
                  String replacement = "\\\\[(?:" + sequenceStr + ")\\\\]";
                  if (optional) {
                      replacement = "(?:" + replacement + ")?";
                  }
                  matcher.appendReplacement(sb, replacement);
                  result = matcher.find();
              } while (result);
              matcher.appendTail(sb);
              expression = sb.toString();
          }
  
          // Order is important here
          expression = expression.replaceAll("[*]([^/(\\\\])", "[^/]*$1"); // '*' not followed by '/', '\\', or '('
          expression = expression.replaceAll("(?<!\\[\\^/\\])[*]", "[^/]*"); // '*' not preceded by '[^/]'
          expression = expression.replaceAll("[/]{2,}$", "(?:/[^/]*)*"); // ending '//'
          expression = expression.replaceAll("[/]{2,}", "(?:/[^/]*)*/"); // other '//'
          return expression;
      }