What's the difference between these RegEx

前端 未结 3 1600
温柔的废话
温柔的废话 2020-12-10 23:07
  1. (\\d+|) vs (\\d+)?
  2. [\\w\\W] vs [\\d\\D] vs .

Is there any difference between t

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 23:51

    [\w\W] and [\d\D] are used in languages like JavaScript in which there isn't a dotall option. It matches all characters, including newlines, unlike . which matches everything but a newline.

       \w\W or \d\D   -> matches everything including newline characters
                  .   -> matches everything except newline characters unless 
                         's' (dotall modifier) is specified 
    (\d+|) or (\d+)?  -> matches 1 or more digits OR any position (null)
                         It could simply be written as '(\d*)'
    

提交回复
热议问题