Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final String EMPTY_STRING = "";

    /**
     * Helper method trimming the trimString pattern from the text input parameter
     * 
     * @param trimString
     *            regex pattern
     * @param text
     *            text to be cleaned
     * @return the input text with any occurrences of the trimString pattern removed.
     */
    private static String trimStringFromText(String trimString, String text) {
        if (trimString != EMPTY_STRING) {
            Pattern trimPattern = Pattern.compile(trimString);
            Matcher matcher = trimPattern.matcher(text);

            while (matcher.find()) {
                // System.out.println(matcher.group());
                text = text.replace(matcher.group(), EMPTY_STRING);
            }
        }
        return text;
    }
}