简体   繁体   中英

simple javascript regex question

How can I match the following pattern?

"anything123.anythingelse"

Alphanum of any length, with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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