Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the regular expressions that filter out letters, numbers and Chinese in Java

Shulou Source: shulou.com Published: 2022-06-02 10:28:24 09月30日 Update

How to understand Java to filter out letters, numbers and Chinese regular expressions, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

1. Filter out regular expressions of letters, numbers and Chinese in Java

(1) filter out the regular expression of letters

[^ (A-Za-z)]

(2) filter out the regular expression of the number

[^ (0-9)]

(3) filter out the regular expressions in Chinese

[^ (\\ u4e00 -\\ u9fa5)]

(4) filter out regular expressions of letters, numbers and Chinese.

[^ (a-zA-Z0-9\\ u4e00 -\\ u9fa5)]

2. Instance source code

/ * *

* @ Title:FilterStr.java

* @ Package:com.you.dao

Filter numbers, letters and Chinese in * @ Description:Java

* @ Author: Liu

* @ date: 7:18:20 on March 12, 2014

* @ Version V1.2.3

, /

Package com.you.dao

/ * *

* @ Class name: FilterStr

* @ description: regular expressions filter numbers, letters, and Chinese

* @ Author: Liu

* @ date: 7:18:20 on March 12, 2014

, /

Public class FilterStr

{

/ * *

*

* @ Title: filterNumber

* @ Type: FilterStr

* @ date: 7:23:03 on March 12, 2014

* @ Description: filter out numbers

* @ param str

* @ return

, /

Public static String filterNumber (String number)

{

Number = number.replaceAll ("[^ (0-9)]", "")

Return number

}

/ * *

*

* @ Title: filterAlphabet

* @ Type: FilterStr

* @ date: 7:28:54 on March 12, 2014

* @ Description: filter out letters

* @ param alph

* @ return

, /

Public static String filterAlphabet (String alph)

{

Alph = alph.replaceAll ("[^ (A-Za-z)]", "")

Return alph

}

/ * *

*

* @ Title: filterChinese

* @ Type: FilterStr

* @ date: 9:12:37 on March 12, 2014

* @ Description: filter out Chinese

* @ param chin

* @ return

, /

Public static String filterChinese (String chin)

{

Chin = chin.replaceAll ("[^ (\\ u4e00 -\\ u9fa5)]", ")

Return chin

}

/ * *

*

* @ Title: filter

* @ Type: FilterStr

* @ date: 9:17:22 on March 12, 2014

* @ Description: filter out letters, numbers and Chinese

* @ param character

* @ return

, /

Public static String filter (String character)

{

Character = character.replaceAll ("[^ (a-zA-Z0-9\\ u4e00 -\\ u9fa5)]", ")

Return character

}

/ * *

* @ Title: main

* @ Type: FilterStr

* @ date: 7:18:22 on March 12, 2014

* @ Description:

* @ param args

, /

Public static void main (String [] args)

{

/ * *

* declare the string you

, /

String you = "^ & ^ & ^ you123 $% $% Hello"

/ * *

* call the method to filter out numbers

, /

You = filterNumber (you)

/ * *

* print the result

, /

System.out.println ("filter out numbers:" + you)

/ * *

* declare the string hai

, /

String hai = "¥%. 4556ahihdjsadhjexamples% Hello, wewewe"

/ * *

* call the method to filter out letters

, /

Hai = filterAlphabet (hai)

/ * *

* print the result

, /

System.out.println ("filter out letters:" + hai)

/ * *

* declare the string dong

, /

String dong = "$% $% $Zhang 34584yuojk @ #% ¥#% …% &"

/ * *

* call the method to filter out Chinese

, /

Dong = filterChinese (dong)

/ * *

* print the result

, /

System.out.println ("filter out Chinese:" + dong)

/ * *

* declare the string str

, /

/ * *

* call the method to filter out letters, numbers and Chinese

, /

Str = filter (str)

/ * *

* print the result

, /

System.out.println ("filter out letters, numbers and Chinese:" + str)

}

}

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Letters numbers Chinese regular expressions characters strings methods results Hello Zhang San Li Si help clarity content examples for this articles novices more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info Xiaomi Shulou Technology Docker