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 pattern = "(\\.[a-zA-Z0-9]{2,6}$)";

    public static String getFileName(String fileName) {

        Pattern p_ext = Pattern.compile(pattern);
        Matcher m_ext = p_ext.matcher(fileName);

        if (m_ext.find()) {
            return fileName.substring(0, fileName.indexOf(m_ext.group()));
        } else {
            return fileName;
        }
    }
}