本文介绍了这些正则表达式有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. (\d+|) vs (\d+)?
  2. [\w\W] vs [\d\D] vs .
  1. (\d+|) vs (\d+)?
  2. [\w\W] vs [\d\D] vs .

这些常规正则表达式之间有什么区别吗?应该选择哪一个?

Is there any difference between these regular regex? Which one should be chosen?

我正在使用 JavaScript.

I'm using Javascript.

推荐答案

[\w\W][\d\D] 用于 JavaScript 等语言其中没有 dotall 选项.它匹配所有字符,包括换行符,不同于 . 匹配所有换行符.

[\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*)'

这篇关于这些正则表达式有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 13:20