关于正则表达式的一个菜鸟问题 vendition lead secretary 限定某文本框中只能写这3个字符串 允许什么也不写 但是最多只能写一个我用 "[(vendition)(lead)(secretary)]?"为什么不行呢?求大神!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 属于明显写错了吧,应该是:"((vendition)|(lead)|(secretary))?" 大神,那我 [(vendition)(lead)(secretary)]? 是变成什么意思了? [(ab)(cd)]被理解为了 ( or a or b or c or d or ) "[(vendition)(lead)(secretary)]?"意义是两种:◎ 可以为:啥都不写◎ 可以为下列符号任意一个:(vendito)lascry [ ] 在正则表达式中称为字符组(character class),表示匹配其中的一个字符,也就是说所能匹配的字符长度仅为 1你这个得改成:(?:vendition|lead|secretary)? 采用 alternative 语法“|”就可以了。 那些括号可以省略的public class zjbds { public static void main(String[] args){ System.out.println("vendition".matches( "vendition|lead|secretary")); }} 不好意思,没看清题意,只能省略一对吧public class zjbds { public static void main(String[] args){ System.out.println("".matches( "(vendition|lead|secretary)?")); System.out.println("vendition".matches( "(vendition|lead|secretary)?")); System.out.println("venditionlead".matches( "(vendition|lead|secretary)?")); }} 关于正则表达式可以参考下面这些帖子:Java正则表达式教程http://topic.csdn.net/u/20080306/17/f37a1818-3968-49b4-8f79-e5564486d63e.html请解释一下正则的相关内容http://topic.csdn.net/u/20080627/14/8a91b33a-f35c-4303-85b5-e0a8da462202.html求个可以代替IsNumeric的正则表达式http://topic.csdn.net/u/20080520/19/175eb3fa-e3b0-4330-b274-e7e9dabc93c0.html确保字符串是1-100的数,怎么写正则?http://topic.csdn.net/u/20080503/01/3c82b040-43b9-4b44-847d-07b366285957.html正则表达式的问题http://topic.csdn.net/u/20080325/17/fb7a3e8d-029a-4d8e-89ae-77a9d28ec301.html ◎ 可以为下列符号任意一个:(vendito)lascry 大神 这是什么意思? 求助!JAVA图像 对头发染色 需要一个js的正则!但是他们都不会!我想这里有火龙果就又来了 求教对jdk精通的人 帮忙看一下为什么JApplet无法在IE里显示 判断Socket连接是否正常的问题 !!!用robot.createScreenCapture(ScreenRect)捕捉屏幕的时候为什么捕捉不到鼠标!!!! 请问我想用eclipse开发桌面应用程序需要什么插件 关于java编译器 在构造jtable时,怎样向它传递数组或变量值!!! IE 6.0?为什么我的applet 不能显示? 求高手指点 enum的方法valueof(String)和values()的问题
被理解为了
( or a or b or c or d or )
◎ 可以为:啥都不写
◎ 可以为下列符号任意一个:(vendito)lascry
public class zjbds {
public static void main(String[] args){
System.out.println("vendition".matches( "vendition|lead|secretary"));
}
}
public class zjbds {
public static void main(String[] args){
System.out.println("".matches( "(vendition|lead|secretary)?"));
System.out.println("vendition".matches( "(vendition|lead|secretary)?"));
System.out.println("venditionlead".matches( "(vendition|lead|secretary)?"));
}
}
http://topic.csdn.net/u/20080306/17/f37a1818-3968-49b4-8f79-e5564486d63e.html请解释一下正则的相关内容
http://topic.csdn.net/u/20080627/14/8a91b33a-f35c-4303-85b5-e0a8da462202.html求个可以代替IsNumeric的正则表达式
http://topic.csdn.net/u/20080520/19/175eb3fa-e3b0-4330-b274-e7e9dabc93c0.html确保字符串是1-100的数,怎么写正则?
http://topic.csdn.net/u/20080503/01/3c82b040-43b9-4b44-847d-07b366285957.html正则表达式的问题
http://topic.csdn.net/u/20080325/17/fb7a3e8d-029a-4d8e-89ae-77a9d28ec301.html
◎ 可以为下列符号任意一个:(vendito)lascry 大神 这是什么意思?