如何转义小于登录 javascript/jquery?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8045745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to escape less than sign in javascript/jquery?
提问by 0SX
I'm having an issue that I can't seem to solve myself. I have the following code below:
我遇到了一个我自己似乎无法解决的问题。我有以下代码:
var symbol = {
heart: /<3/gm,
};
I'm trying to search for the heart text symbol but I it can't find it upon searching text. What am I doing wrong here? Thanks.
我正在尝试搜索心形文本符号,但在搜索文本时找不到它。我在这里做错了什么?谢谢。
回答by Sparky
You can try <
in place of <
你可以试试<
代替<
回答by Chris Heald
Seems like it works to me.
似乎对我有用。
symbol = { heart: /<3/gm, };
> Object
"hi there <3".match(symbol.heart)
> ["<3"]
Perhaps your problem lies elsewhere?
也许你的问题出在别处?