也许有人可以帮助我解决这个问题
我有一个字符串,例如"1.something"
,"1.0.something"
或1.0.0.something
问题是我该如何检查某物部分中没有更多的点?
谢谢。
答案 0 :(得分:0)
答案 1 :(得分:0)
const re = /^(\d\.){1,3}([^.]+)$/;
console.log(re.test('1.0.0.somethdfs!!$%^$%ing')); // true
console.log(re.test('1.0.something')); // true
console.log(re.test('1.something')); // true
console.log(re.test('1.0.0.somet.hing')); // false
console.log(re.test('1.0.sometmjhi!!ng')); // true
console.log(re.test('1.somethim.ng')); // false
^ // the start of the string
(\d\.) // a digit followed by a period
{1,3} // between one and three times only
([^.]+) // everything after that doesn't include a period
$ // the end of the string