以'/'结尾的字符串的正则表达式 [英] 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?
推荐答案
您必须对最终的/
进行转义,以使解释器不会认为它终止了RegExp文字:
You must escape the final /
so the interpreter doesn't think it terminates the RegExp literal:
str.match(/\/$/);
这篇关于以'/'结尾的字符串的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文