Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Replace a string that contains wildcards (* and ?) to its regular expression equivalent.
     * @param wildcardString the string to convert.
     * @return the regular expression equivalent to the wildcard string.
     */
    public static String convertWildcardsToRegExp(String wildcardString) {
        return "\\Q" + wildcardString.replace("\\E", "\\\\E").replace("\\Q", "\\\\Q").replace("?", "\\E.\\Q")
                .replace("*", "\\E.*\\Q");
    }
}