Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.Log;

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

public class Main {
    public static String parseMessageForMeetingCode(String message) {
        String[] searchPattern = new String[] { "[Pp]ass[\\D]*[0-9\\s]{6,}", "[Pp][Ii][Nn][\\D]*[0-9]{6,}",
                "[Pp]arti[\\D]*[0-9]{6,}", "[Pp][wW][\\D]*[0-9]{6,}" };

        String result = searchForPattern(message, searchPattern[0]);
        if (result == null) {
            int count = 1;
            while (count < searchPattern.length) {
                result = searchForPattern(message, searchPattern[count]);
                if (result != null)
                    break;
                count++;
            }
        }
        if (result != null) {
            if (!result.isEmpty()) {
                return getNumber(result);
            }
        }
        return "";
    }

    public static String searchForPattern(String message, String pattern) {

        Pattern first = Pattern.compile(pattern);
        Matcher match = first.matcher(message);
        //Log.i("parseMessageForMeetingID",Integer.toString(match.groupCount()));

        if (match.find()) {
            String str = match.group(0);
            Log.i("searchForPattern", str);
            return str;
        }
        Log.i("searchForPattern", "no match found");
        return null;
    }

    public static String getNumber(String input) {
        if (input == null)
            return "";
        String str = input.replaceAll("\\s+", "");
        Pattern number = Pattern.compile("[0-9]+");
        Matcher matcher1 = number.matcher(str);
        if (matcher1.find())
            return matcher1.group(0);
        return "";
    }
}