[smhdw]
(?i)
s
那么数字可以有一个小数部分(不受限制的小数位数)1s
3m
1.05s
53.1345s
5w
37d
101H
任何人都可以帮忙吗?感谢
答案 0 :(得分:1)
更新:第一个正则表达式在没有经过测试的情况下,在性能上与其他可以实现此目的的模式相当。通过更新参数,在大型文档上可能会更快。减少回溯
^(\d+([sSmMhHdDwW]|\.\d+[sS]))$
^ # Anchors to beginning of line
( # opens capturing group 1
\d+ # any number of digits, one or more
( # opens capturing group 2
[sSmMhHdDwW] # any of s,m,h,d,w (case-insensitive)
| # Alternation for capturing group 2
\. # Literal .
\d+ # any number of digits
[sS] # s (case-insensitive)
) # closes capturing group 2
) # closes capturing group 1
$ # Anchors to end of line
老patthern:
^(\d+(\.\d+)?[sS]|\d+[mMhHdDwW])$
应该符合您的需求
^ # Anchors to beginning of line
( # Open Capturing Group 1
\d+ # any digit, one or more times
( # open capturing group 2
\. # Literal .
\d+ # any number of digits, 1 or more (denoted by +)
) # closes capturing group 2
? # repeats previous group 0 or 1 times, thus optional
s # literal s
| # Alternation
\d+ # any digit, any number of times
[mMhHdDwW] # character class, any of mhdw
) # closes capturing group 1
$ # anchors to end of line