本文介绍了禁用不必要的转义字符:\ / no-useless-escape的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的这个正则表达式,它将检查字符串是否包含链接或URL (即https://eslint.org/docs/rules/no-useless-escape)。使用此正则表达式 /(\b(https?| ftp | file):\ / \ / [-A-Z0-9 +& @#\ /%?=〜_ | !:,。;] * [-A-Z0-9 +& @#\ /%=〜_ |])/ ig ,在运行测试用例时遇到错误对不必要的转义字符\ / no-useless-escape 做出反应。如何禁用此错误,以便我继续测试用例并使用正则表达式。

I have this regex of mine that will check the string if it contains link or url (i.e. https://eslint.org/docs/rules/no-useless-escape). Using this regex /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, I've encountered and error while running my test cases in react about Unnecessary escape character: \/ no-useless-escape. How to disable this eslint-error in order for me to proceed with my test case and use the regex.

感谢您的帮助!

推荐答案

这是中的 + / [-A-Z0-9 + & @#\ /%?=〜_ |!:,。;] [-A-Z0-9 +& @#\ /%= 〜_ |] (不是:\ / \ / 中的那些)。大多数字符不必在字符类(方括号)内转义。这应该等效: /(\b(https?| ftp | file):\ / \ / [-A-Z0-9 +& @#/%?=〜_ | !:,。;] * [-A-Z0-9 +& @#/%=〜_ |])/ ig 所以
参见了解更多信息,但相关部分:

It's the \/ in [-A-Z0-9+&@#\/%?=~_|!:,.;] and [-A-Z0-9+&@#\/%=~_|] (NOT the ones in :\/\/). Most characters do not have to be escaped within a character class (square brackets). This should be equivalent: /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig So See https://www.regular-expressions.info/charclass.html for more info, but the relevant part:

这篇关于禁用不必要的转义字符:\ / no-useless-escape的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:46