match Not empty string by regex - Android java.util.regex

Android examples for java.util.regex:Character Pattern

Description

match Not empty string by regex

Demo Code


//package com.java2s;

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

public class Main {

    private static final String V_NOTEMPTY = "^\\S+$";

    public static boolean Notempty(String value) {
        return match(V_NOTEMPTY, value);
    }/*from  w w  w .  j  a va2s. com*/

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related Tutorials