Skip to content

Instantly share code, notes, and snippets.

@abbashosseini
Last active January 18, 2016 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abbashosseini/ffacc86b4051803e1879 to your computer and use it in GitHub Desktop.
Save abbashosseini/ffacc86b4051803e1879 to your computer and use it in GitHub Desktop.
Check StringLanguage in java With Regex
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by abbas on 9/21/15.
*/
public class LanguageType {
public static boolean isPersian(String s){
Pattern RTL_CHARACTERS =
Pattern.compile("[\u0600-\u06FF\u0750-\u077F\u0590-\u05FF\uFE70-\uFEFF]");
Matcher matcher = RTL_CHARACTERS.matcher(s);
return matcher.find();
}
public static boolean isGreek(String s){
Pattern CHARACTERS =
Pattern.compile("^[α-ωΑ-Ω\s]*$");
Matcher matcher = CHARACTERS.matcher(s);
return matcher.find();
}
public static boolean isArabic(String s){
Pattern CHARACTERS =
Pattern.compile("[\u0600-\u06FF]");
Matcher matcher = CHARACTERS.matcher(s);
return matcher.find();
}
public static boolean isLatin(String s){
Pattern CHARACTERS =
Pattern.compile("[[\p{L}\s]+");
Matcher matcher = CHARACTERS.matcher(s);
return matcher.find();
}
public static boolean isEnglish(String s){
Pattern LTR_CHARACTERS =
Pattern.compile("[A-Za-z]+");
Matcher matcher = LTR_CHARACTERS.matcher(s);
return matcher.find();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment