簡體   English   中英

Javascript正則表達式匹配字符串以字母或數字開頭

[英]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()更簡單。
它只返回falsetrue ,而.match()返回null或數組。

.test()和.match()之間的更多信息差異

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM