Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for a string that ends with '/'

The regular expression for a string that ends with '/' is the following:

str.match(//$/) -- javascript syntax

but the // makes the compiler think it's a comment. how to work around this?

like image 751
Laguna Avatar asked Dec 21 '22 03:12

Laguna


1 Answers

You must escape the final / so the interpreter doesn't think it terminates the RegExp literal:

str.match(/\/$/);
like image 200
maerics Avatar answered Dec 23 '22 15:12

maerics