Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.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 如何使用正则表达式获取Aadhar编号的最后一个字符_Javascript_Jquery_Regex - Fatal编程技术网

Javascript 如何使用正则表达式获取Aadhar编号的最后一个字符

Javascript 如何使用正则表达式获取Aadhar编号的最后一个字符,javascript,jquery,regex,Javascript,Jquery,Regex,我有一个阿达尔号码 var temb=“xxxxxxxx 5267” 我需要获取最后4位数字(5267) 我尝试了(.{3})\s*$它不起作用。您可以使用带负号的切片方法(通过反向匹配字符): var temb=“xxxxxxxx 5267”; console.log(temb.slice(-4))使用这个 [0-9]{4}$ 检查这里的演示:正则表达式运行良好。你用了正确的方法来做这件事吗 const temb=“xxxxxxxx 5267” 常量res=temb.match(/(.

我有一个阿达尔号码

var temb=“xxxxxxxx 5267”

我需要获取最后4位数字
(5267)


我尝试了
(.{3})\s*$
它不起作用。

您可以使用带负号的切片方法(通过反向匹配字符):

var temb=“xxxxxxxx 5267”;
console.log(temb.slice(-4))
使用这个

[0-9]{4}$


检查这里的演示:

正则表达式运行良好。你用了正确的方法来做这件事吗

const temb=“xxxxxxxx 5267”
常量res=temb.match(/(.{4})\s*$/g)

console.log(res[0])
您可以在此处替换正则表达式:

const temb=“xxxxxxxx 5267”
const num=temb.replace(/^.*(\d{4})$/,“$1”);

console.log(num)或者您可以将您的代码从(.{3})\s*$修改为(.{4})\s*$