求正则判断0到20之间的整数,包括20,不包括0
//从abc12abc中匹配出数字
/(\D|^)0*(1?[1-9]|[12]0)(\D|$)/
//使用test方法测试一个数字,可以使用0开头
/^0*(1?[1-9]|[12]0)$/
/^(1)\d{1}$|^[1-9]{1}$|^20$/
/^[1]?[1-9]{1}$|^20$/
is1to20 = str => /^(?:[1-9]|1[0-9]|20)$/.test(str);
// 测试:
new Array(20)
.join(' ')
.split(' ')
.map((_,i)=>i+1)
.forEach(_=>console.log(_, is1to20(_.toString())))