javascript - regular expression for checking .css file -


i wanna check file css file or not using regular expression. tried

new regexp(".css$").test("a.css"); //true  

but matching filename.acss correct. want regex match valid .css file only. need following cases .

new regexp(".css$").test("a.acss"); //false new regexp(".css$").test(".css"); //false new regexp(".css$").test("a.cssa"); //false new regexp(".css$").test("a.css"); //true  

.: (the decimal point) matches single character except newline character.

you need escape . preceding \ match . literal.

var regex = /.\.css$/; // /\s+\.css$/; // /[\w\d]+\.css$/ regex.test("a.css"); 

exaples

var regex = /.\.css$/;    alert(regex.test("a.acss")); // false  alert(regex.test(".css")); // false  alert(regex.test("a.cssa")); // false  alert(regex.test("a.css")); // true


Comments