0

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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

and [\w] is the same as \w ;)
if the alphanumeric parts can be zero length, it'd be a * instead of a + in both cases

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.