关于正则表达式的一个初学者有关问题
关于正则表达式的一个菜鸟问题
vendition lead secretary 限定某文本框中只能写这3个字符串 允许什么也不写 但是最多只能写一个
我用 "[(vendition)(lead)(secretary)]?"为什么不行呢?求大神!!!
------解决方案--------------------
[ ] 在正则表达式中称为字符组(character class),表示匹配其中的一个字符,也就是说所能匹配的字符长度仅为 1
你这个得改成:
(?:vendition|lead|secretary)? 采用 alternative 语法“|”就可以了。
------解决方案--------------------
不好意思,没看清题意,只能省略一对吧
vendition lead secretary 限定某文本框中只能写这3个字符串 允许什么也不写 但是最多只能写一个
我用 "[(vendition)(lead)(secretary)]?"为什么不行呢?求大神!!!
------解决方案--------------------
[ ] 在正则表达式中称为字符组(character class),表示匹配其中的一个字符,也就是说所能匹配的字符长度仅为 1
你这个得改成:
(?:vendition|lead|secretary)? 采用 alternative 语法“|”就可以了。
------解决方案--------------------
不好意思,没看清题意,只能省略一对吧
- Java code
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)?")); } }
------解决方案--------------------