简体   繁体   English

简单的javascript正则表达式问题

[英]simple javascript regex question

How can I match the following pattern? 如何匹配以下模式?

"anything123.anythingelse" “任何东西123.anythingelse”

Alphanum of any length, with exactly 1 "." 任何长度的Alphanum,正好为1“。” in the middle, and then alphanum of any length? 在中间,然后是任意长度的字母数字?

Thanks. 谢谢。

That would then be /[a-z0-9]+\\.[a-z0-9]+/i . 那将是/[a-z0-9]+\\.[a-z0-9]+/i The /i is the case insensitive modifier. /i是不区分大小写的修饰符。

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+/ . 如果可以允许使用下划线,则可以将其缩短:/ /\\w+\\.\\w+/ . /\\w+\\.\\w+/ The \\w is the same as [a-zA-Z0-9_] . \\w[a-zA-Z0-9_]

See also : http://www.regular-expressions.info 另请参阅http : //www.regular-expressions.info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM