最简单的形式:
^\w+(,\w+)*$
I need to restrict only alphabets. How can I do that ?
使用正则表达式(包括示例unicode字符范围):
^[\u0400-\u04FFa-zA-Z ]+(,[\u0400-\u04FFa-zA-Z ]+)*$
用法示例:
public static void main (String[] args) throws java.lang.Exception
{
String regex = "^[\u0400-\u04FFa-zA-Z ]+(,[\u0400-\u04FFa-zA-Z ]+)*$";
System.out.println("abc,xyz,pqr".matches(regex)); // true
System.out.println("text1,text2,".matches(regex)); // false
System.out.println("ЕЖЗ,ИЙК".matches(regex)); // true
}