In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.