![](/img/trans.png)
[英]Regex Expression to remove certain characters from string expect at the start and end
[英]Regex expression for start and end with characters in between numbers
我在 javascript 中有要求,其中單詞的開頭和結尾是數字之間的字符。 例如 S652354536667U
我試過模式
(/[A-Z]\d+[A-Z]$/).test(S652354536667U) // returns true ok
(/[A-Z]\d+[A-Z]$/).test(S65235Y4536667U) // returns true needed false
但它允許像 S65235Y4536667U 之間的字符被接受。
任何幫助表示贊賞。
謝謝
您需要在正則表達式的開頭放置一個插入符號,以指示第一個字母位於字符串的開頭,即:
^[A-Z]\d+[A-Z]$
你一開始就離開了插入符號。
["S652354536667U", "S65235Y4536667U"].forEach(item => { console.log(/^[AZ]\d+[AZ]$/.test(item)) })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.