开发者

Check a javascript variable matches a substring using regex expression

I have a JavaScript variable that contains string value. I want to check whether the string contains UID_PK in it. How can I match t开发者_如何学Gohis string to match the substring "UID_PK" using regex expression?

For example var id="UID_PK:1234"


No regular expressions needed, you can use indexOf [docs]:

if(id.indexOf("UID_PK") > -1) {
    // id contains "UID_PK"
}


var id="UID_PK:1234"
if( id.match( /UID_PK/ )) alert( 'match' );

next time try to read dome documentation on regex in javascript , this is the most simple example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜