关于#正则#的问题,如何解决?

实现一个正则
由字母数字下划线组成,且不能以数字或下划线开头!
十分感谢


/^(?![\d_])\w+$/gi

img

[a-zA-Z][a-zA-Z_\d]*

/^[a-zA-Z][a-zA-Z0-9_]*$/

示例:

const strings = ["abc123", "1abc2", "_abc", "abc_", ""];

const pattern = /^[a-zA-Z][a-zA-Z0-9_]*$/;

for (const s of strings) {
  if (pattern.test(s)) {
    console.log(`${s} matches the pattern!`);
  } else {
    console.log(`${s} does not match the pattern!`);
  }
}

/^[a-zA-Z][a-zA-Z0-9_]*$/