Using RegEx to check if a string contains another String - Android java.util.regex

Android examples for java.util.regex:Pattern Search

Description

Using RegEx to check if a string contains another String

Demo Code

import android.annotation.SuppressLint;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static boolean containsStringRegex(String total, String reg) {
        Pattern p = Pattern.compile(reg);
        Matcher m = p.matcher(total);
        if (m.find()) {
            return true;
        }//from w  ww .  jav  a 2 s .c  o m
        return false;
    }

}

Related Tutorials