Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; import android.widget.EditText; public class Main { public static boolean isDeletePng(EditText input, int cursor) { String st = "[p/_000.png]"; String content = input.getText().toString().substring(0, cursor); if (content.length() >= st.length()) { String checkStr = content.substring(content.length() - st.length(), content.length()); String regex = "\\[[^\\]]+\\]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(checkStr); return m.matches(); } return false; } }