search
HomeJavaJavaBaseIntroduction to the method of judging whether it is English in java

Introduction to the method of judging whether it is English in java

When doing development, we often need to judge whether a certain character or string is in English. Let's take a look at the method of judging whether it is English in Java: (Recommended : java video tutorial)

1. Determine whether all the English words in the string are in English

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

2. Extract all the English words in the string

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

3. Determine whether the string contains English

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

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Introduction to the method of judging whether it is English in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.