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 {
    /**
     * A {@link Pattern} that will match checksums enclosed in brackets ("[]" or "()"). A checksum string is a hex number with at least 8 digits. Capturing group 0 will contain the matched checksum string.
     */
    public static final Pattern EMBEDDED_CHECKSUM = Pattern.compile("(?<=\\[|\\()(\\p{XDigit}{8})(?=\\]|\\))");

    public static String getEmbeddedChecksum(CharSequence string) {
        Matcher matcher = EMBEDDED_CHECKSUM.matcher(string);
        String embeddedChecksum = null;

        // get last match
        while (matcher.find()) {
            embeddedChecksum = matcher.group();
        }

        return embeddedChecksum;
    }
}