• 潘华引Simon Pan
    2018-08-21
    月份和日期的正则是不是考虑下超出上限的情况,比如出现13月或者45日

    作者回复: 正则的编写要根据具体需求来决定,如果数据“干净”,比如从一篇论文里面取月份日期可以使用[0-9][0-9]形式,因为数据都是事先处理过的
    但是如果要使用正则判断用户输入的月份日期是不是合法就要用[1-9]|(1[012])和[1-9]|([12][0-9])|(3[01])这样的形式,
    考虑到日期还有2月29这种输入,正则其实并不是判断用户输入年月日的最优解,可以考虑使用下拉列表或者程序逻辑判断

    
     2
  • Guti
    2018-10-05
    \s不是说错了,

    \s
    For Unicode (str) patterns:
    Matches Unicode whitespace characters (which includes [ \t\n\r\f\v], and also many other characters, for example the non-breaking spaces mandated by typography rules in many languages). If the ASCII flag is used, only [ \t\n\r\f\v] is matched (but the flag affects the entire regular expression, so in such cases using an explicit [ \t\n\r\f\v] may be a better choice).
    For 8-bit (bytes) patterns:
    Matches characters considered whitespace in the ASCII character set; this is equivalent to [ \t\n\r\f\v].
    \S
    Matches any character which is not a whitespace character. This is the opposite of \s. If the ASCII flag is used this becomes the equivalent of [^ \t\n\r\f\v] (but the flag affects the entire regular expression, so in such cases using an explicit [^ \t\n\r\f\v] may be a better choice).
    展开

    作者回复: \s 匹配空白
    \S 匹配非空白
    空白指制表符\t 换行符\n 等

    
     1
  • Serendipity
    2019-10-23
    \d 不是匹配一串数字,相当于 [0-9]+ 吗?为什么还要在 d 后面加上一个 + 呢?

    作者回复: \d 相当于 [0-9]

    
    
  • 硕杨Sxuya
    2018-11-15
    强烈疑惑,为什么第一组的数字标记不是 ```group(0)```,而是 ```group(1)```,一点都不程序员思路
    
    
我们在线,来聊聊吧