[英]Javascript regular expression match string to start with letter or number
我想看看我的字符串是以字母還是數字開頭。 我想我很親近,有人可以幫助我嗎?
if(thestring.match("/^[\pL\pN]/"))
采用:
^[A-Z0-9]
使用不區分大小寫的修飾符:
if(thestring.match(/^[A-Z0-9]/i)) {}
\\pL
和\\pN
是PCRE短代碼,不適用於Javascript。
if(/^[a-z0-9]/i.test(thestring)) {
//do something
}
.test()
更簡單。
它只返回false
或true
,而.match()
返回null
或數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.