SOURCE

let word = 'C12345678'
let string = 'Carl went to buy a car 10 but had forgotten his credit card.'
var instancesOfWord = string.match(new RegExp('\\b'+ 10 +'\\b'));
// /^C\d{8}$/
console.log('instancesOfWord',instancesOfWord)

let str = 'C12345678'
let reg = new RegExp(`^C\\d{${8}}$`)
console.log(reg.test(str))
console 命令行工具 X clear

                    
>
console