user1775888 user1775888 - 19 days ago 4
Javascript Question

How to use specific website in regex

I want the regex pattern to only match

I have tried add
before www.
but it shows error..

Did I miss anything ?

hope this result true true false false

var str = '';

var regexPattern = /([www]+\.)+[\ba9\.com\b]/;
var result = regexPattern.test(str);

only regex. not use split or other method


This Regex sould do the trick:


The ´?´ quantifier, to make the group optional goes after the group, not before.

Bonus: I always test my regex with, you should try it. You´ll find a handy cheat sheet there too.