Home > Java > Java Basics > body text

How to determine whether a string contains English in java

王林
Release: 2019-11-22 13:28:50
Original
6736 people have browsed it

How to determine whether a string contains English in java

1. Determine whether the string is all in English

boolean result = str.matches("[a-zA-Z]+");    //true:全文英文
str.matches("[a-zA-Z0-9]+")   //判断英文和数字
Copy after login

2. Extract all the English in the string

str = str.replaceAll("[^a-z^A-Z]", "");    //"[^a-z^A-Z]"改为"[^a-z^A-Z^0-9]"即获取所有的英文和数字
Copy after login

3. Determine the string Does it contain English

String regex = ".*[a-zA-z].*";
str.matches(regex);   //true:含有英文
Copy after login

Recommended tutorial: java introductory tutorial

The above is the detailed content of How to determine whether a string contains English in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!