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

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

问题描述

我的问题是一个简单的问题,它是关于正则表达式的转义。你必须在正则表达式中摆脱正斜杠 / 你会如何去做?

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天全站免登陆