Java Regex Create toRegEx(String input)

Here you can find the source of toRegEx(String input)

Description

Convert the incoming string to a regular expression.

License

Open Source License

Parameter

Parameter Description
input the input string

Return

the converted string

Declaration

public static String toRegEx(String input) 

Method Source Code

//package com.java2s;
/*/* w  w  w.jav  a2  s. c  om*/
 *  Version: 1.0
 *
 *  The contents of this file are subject to the OpenVPMS License Version
 *  1.0 (the 'License'); you may not use this file except in compliance with
 *  the License. You may obtain a copy of the License at
 *  http://www.openvpms.org/license/
 *
 *  Software distributed under the License is distributed on an 'AS IS' basis,
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 *  for the specific language governing rights and limitations under the
 *  License.
 *
 *  Copyright 2005 (C) OpenVPMS Ltd. All Rights Reserved.
 *
 *  $Id$
 */

public class Main {
    /**
     * Convert the incoming string to a regular expression. This means
     * escaping the '.' and converting all the '*' to '.*'
     *
     * @param input the input string
     * @return the converted string
     */
    public static String toRegEx(String input) {
        return input.replace(".", "\\.").replace("*", ".*");

    }
}

Related

  1. toRegex(String includes)
  2. toRegex(String name)
  3. toRegex(String param)
  4. toRegex(String wildcard)
  5. toRegExFormat(String pattern)