regexp 16-19

by A A

JavaScript

/* var str = 'hellowodasd1212311311223123312asdasdadasd'; 
var match =  str.match(/[0-9]{16,19}/);
console.log("match", match && match.index, match && match[0].length)
var new1 = str.replace(/[0-9]{16,19}/, "0000000000000000000");
console.log("str", str)
console.log("new1", new1) */
/* console.log(/(?<!\d)\d{16,19}(?!\d)/.test("1234567890123456789"))
console.log(/(?<!\d)\d{16,19}(?!\d)/.test("123456789012345"))
console.log(/(?<!\d)\d{16,19}(?!\d)/.test("a1234567890123456789a"))
console.log(/(?<!\d)\d{16,19}(?!\d)/.test("a12345678901234567890a"))
 */
 
const test = (val, shouldBe) => {
 val = " " + val + " ";
 /* let check = val.match(/\D(\d{16,19})\D/); */
 /* let check = val.replace(/\D(\d{16,19})\D/, "XXX"); */
 let check = /\D(\d{16,19})\D/.test(val);
 console.log("test = ", check, "=", shouldBe);
}

test("a123456789012345a", "false");
test("a1234567890123456a", "true");
test("1234567890123456a", "true");
test("a1234567890123456", "true");
test("a1234567890123456789a", "true");
test("a12345678901234567890a", "false");
test("1234567890123456789a", "true");
test("a1234567890123456789", "true");