2014年5月15日星期四

Great God help seeking regular write a regular expression

questions are as follows
eg: Xiao Ming , Xiao Wu , junior , java
contents appear in this format in the above example

spaces can not appear before and after each keyword separated by a comma , the comma in English can be, can not appear before the space after the comma , the length of each keyword must not be less than two and no spaces , followed by the last keyword can not have a comma is not allowed except for Chinese and English alphabet plus 26 other characters appear comma
For example : Xiao Ming , (space ) Small & # ¥ Wu, big ( blank ) three , java, & * #% ¥, regular filtered became Xiaoming , Xiao Wu , junior , java

ask God to write a regular large , more anxious , thank you

------ Solution ------------------------------------ --------
tinkering
string.replaceAll("[^a-zA-Z\\u4e00-\\u9fa5,,]|[,,]$","").replaceAll("[,,]{2,}",",").replaceAll("[,,]$","")

------ For reference only ----------------------------------- ----
match regular :
([a-zA-Z \ u4e00-\ u9fa5] {2,} [,]) * [a-zA-Z \ u4e00-\ u9fa5] {2,}
filtering methods :

string.replaceAll("[^a-zA-Z\\u4e00-\\u9fa5,,]","").replaceAll("[,,]$","")

------ For reference only ----------------------------------- ----

can , thank the great God , knot posted .

没有评论:

发表评论