Last active
January 18, 2016 18:40
-
-
Save abbashosseini/ffacc86b4051803e1879 to your computer and use it in GitHub Desktop.
Check StringLanguage in java With Regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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