Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我希望下面的正则表达式返回16个字符_Javascript_Regex - Fatal编程技术网

Javascript 我希望下面的正则表达式返回16个字符

Javascript 我希望下面的正则表达式返回16个字符,javascript,regex,Javascript,Regex,我有下面的代码,希望在“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') } 是否可以不执行substr(0,10)?为了精确匹

我有下面的代码,希望在“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')
}

是否可以不执行
substr(0,10)

为了精确匹配10个字符,我们可以使用
{10}

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

尝试
value.match(/LAST=([^?&]{10})$/i)
value.match(/LAST=([^?&]{10})$/i)
。现在还不清楚:你想要10个或更多?您说您需要在标题中返回16个字符,在问题正文中返回10个字符。抱歉,仅返回10个字符。。我试试看,谢谢。我没法理解正则表达式,但字符串末尾有10个字符?或者获得10个字符,然后忽略其余的字符,即使有11、12个字符?仅10个,如果多于或少于10个,则不返回任何内容。请使用清晰的英语?“只有10个,如果超过或少于10个,则不返回任何内容”是什么意思?