正则表达式仅适用于字母(无特殊字符)

时间:2019-02-22 18:54:48

标签: javascript regex class tags match

我正在尝试重写选择器功能$("selector")的简单版本。我有正则表达式通过传入的选择器中的ID,类或标记名来标识元素,定义如下:

  const idRegex = /#(\w+)/g;
  const tagRegex = /^[a-zA-Z]*/g;
  const classRegex = /\.(\w+)/g;

当我针对.some_class测试tagRegex时,出于某种原因有匹配吗? 链接到正则表达式测试:https://regex101.com/r/vtagpw/1

我使用了错误的正则表达式吗?我应该改用什么?

0 个答案:

没有答案