开发者

simple javascript regex question

开发者 https://www.devze.com 2023-01-03 19:17 出处:网络
How can I match the following pattern? \"anything123.anythingelse\" Alphanum of any length, wi开发者_StackOverflowth exactly 1 \".\" in the middle, and then alphanum of any length?

How can I match the following pattern?

"anything123.anythingelse"

Alphanum of any length, wi开发者_StackOverflowth exactly 1 "." in the middle, and then alphanum of any length?

Thanks.


That would then be /[a-z0-9]+\.[a-z0-9]+/i. The /i is the case insensitive modifier.

var match = /[a-z0-9]+\.[a-z0-9]+/i.test(string);
alert(match); // true or false.

If you can allow underscores, this can be done shorter: /\w+\.\w+/. The \w is the same as [a-zA-Z0-9_].

See also: http://www.regular-expressions.info

0

精彩评论

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