The regular expression for a string that ends with '/' is the following:
str.match(//$/) -- javascript syntax
but the // makes the piler think it's a ment. how to work around this?
The regular expression for a string that ends with '/' is the following:
str.match(//$/) -- javascript syntax
but the // makes the piler think it's a ment. how to work around this?
Share Improve this question asked Jan 12, 2012 at 21:10 LagunaLaguna 3,8765 gold badges29 silver badges42 bronze badges 2- 1 what about this : stackoverflow./questions/1569295/… – Afshin Commented Jan 12, 2012 at 21:12
- Oh god, so many people typing the same thing but no one checking their answer first! – Gareth Commented Jan 12, 2012 at 21:13
4 Answers
Reset to default 6You must escape the final /
so the interpreter doesn't think it terminates the RegExp literal:
str.match(/\/$/);
You need to escape the slash:
str.match(/\/$/)
Use the escape character (\
) to specify a literal / as in:
str.match(/\/$/);
You'll need to escape the slash
str.match(/\/$/);
If you want to match a string that ends with slash, you may want to include the actual string too;
str.match(/.*\/$/);