我希望以下正则表达式返回16个字符

我有以下代码,希望仅能在'LAST ='之后返回10个字符。如果没有10个字符,则不返回任何字符。

const value = 'LAST=uirndheusnrm38f6xxxxxxx'
const m = value.match(/LAST=([^\?&]+)/i)

if (m)
{
  console.log('i know it matched LAST= and returned the next 10 chars')
}

Is it possible without doing a substr(0,10) ?

评论
  • yeahlife
    yeahlife 回复

    In order to match exactly 10 characters we can use {10}:

    const m = value.match(/LAST=([^\?&]{10})/i);