Java tutorial
//package com.java2s; import android.text.TextUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String patternCode(String patternContent) { if (TextUtils.isEmpty(patternContent)) { return null; } Pattern p = Pattern.compile("(?<!\\d)\\d{4}(?!\\d)"); Matcher matcher = p.matcher(patternContent); if (matcher.find()) { return matcher.group(); } return null; } }