JavaScript 检查字符串是否包含连续三个数字
function hasThreeDigits(str) {/n for (let i = 0; i < str.length - 2; i++) {/n if (//d{3}/.test(str.slice(i, i + 3))) {/n return str.slice(i, i + 3);/n }/n }/n return false;/n}/n/n// 示例测试/nconsole.log(hasThreeDigits('abc123def')); // '123'/nconsole.log(hasThreeDigits('1a2b3c')); // '1a2'/nconsole.log(hasThreeDigits('hello')); // false
原文地址: https://www.cveoy.top/t/topic/nm3S 著作权归作者所有。请勿转载和采集!