我正在使用java编程语言。我想要编写一个正则表达式,它将与字符串开头的specific string(e.g. boy)
或数字(from 5-8)
匹配。成功的投入只应是:
怎么做?
在所有其他情况下,返回值应为false.Any解决方案或建议将不胜感激。
发布于 2014-01-12 14:36:57
您可以使用这个regex:
^(boy|[5-8])
解释:
^ assert position at start of the string
1st Capturing group (boy|[5-8])
1st Alternative: boy
boy matches the characters boy literally (case sensitive)
2nd Alternative: [5-8]
[5-8] match a single character present in the list below
5-8 a single character in the range between 5 and 8
https://stackoverflow.com/questions/21075879
复制相似问题