简体   繁体   English

正则表达式javascript如何写4位数字后跟感叹号“4444!”

[英]Regular expression javascript how to write 4 digits followed by an exclamation mark "4444!"

I tired to write a regular expression where regular expression match 4 digits and follow by exclamation mark as in "4444!"我厌倦了写一个正则表达式,其中正则表达式匹配 4 位数字,后跟感叹号,如“4444!”

this is what I got so far这是我到目前为止所得到的

function checkAcc(acc){
    regx = /^\d{4}$(?=!)/
    return regx.test(acc)
}

I tired and 4 digits part work but can't get the exclamation mark to work.我累了,4 位数字部分工作,但不能让感叹号工作。

thank you very much for your time answer this~非常感谢您花时间回答这个问题~

Try this one:试试这个:

regx = /^\d{4}(?=!$)/

Or, this one, if you do not have any plan to capture the matching.或者,这个,如果您没有任何计划来捕获匹配。

regx = /^\d{4}!$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM