在正则表达式中转义正斜杠 [英] Escaping a forward slash in a regular expression

查看:72
本文介绍了在正则表达式中转义正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,是关于正则表达式转义的.您是否必须在正则表达式中对正斜杠 / 进行转义?你会怎么做?

My question is a simple one, and it is about regular expression escaping. Do you have to escape a forward slash / in a regular expression? And how would you go about doing it?

推荐答案

什么上下文/语言?某些语言使用 / 作为模式分隔符,所以是的,您需要转义它,具体取决于哪种语言/上下文.您可以通过在它前面放置一个反斜杠来转义它: / 对于某些语言(如 PHP),您可以使用其他字符作为分隔符,因此您不需要对其进行转义.但是AFAIK在所有语言中, / 唯一的特殊意义是它可能是指定的模式分隔符.

What context/language? Some languages use / as the pattern delimiter, so yes, you need to escape it, depending on which language/context. You escape it by putting a backward slash in front of it: / For some languages (like PHP) you can use other characters as the delimiter and therefore you don't need to escape it. But AFAIK in all languages, the only special significance the / has is it may be the designated pattern delimiter.

这篇关于在正则表达式中转义正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆