我很难创建一个regex (Java)来匹配以下模式:
有效投入:
到目前为止我所拥有的是:
[\\d{1,2}MS?\\s]{7}
它强制长度并允许使用空白空间,但仅此而已。任何帮助都将不胜感激。
发布于 2017-08-22 16:36:57
这个人做的是:
^(?=.{7}$)\\d{1,2}MS?\\s*$解释:
^ : begining of line, not mandatory when using matches()
(?=.{7}$) : lookahead, make sure we have exactly 7 characters
\\d{1,2} : 1 or 2 digits
M : M
S? : optional S
\\s* : 0 or more spaces
$ : end of line, not mandatory when using matches()https://stackoverflow.com/questions/45822917
复制相似问题