正则表达式替换
我有一个字符串:
<代码> 用户/554983490\/另一个+测试+/问题???\/+dhjkfsdf/
我如何编写一个正则表达式来匹配所有前面没有反斜杠的正斜杠?
编辑:有没有办法在不使用负面回顾的情况下做到这一点?
I have a string:
users/554983490\/Another+Test+/Question????\/+dhjkfsdf/
How would i write a RegExp that would match all of the forward slashes NOT preceded by a back slash?
EDIT: Is there a way to do it without using a negative lookbehinds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的正则表达式支持负向后查找:
否则,您将需要匹配
/
之前的字符:这与字符串的开头 (
^
) 或 (|
) 任何其他字符匹配比\
([^\\]
) 作为捕获组 #1()
。然后它匹配后面的文字/
。/
之前的任何字符都将存储在捕获组$1
中,以便在进行替换时可以将其放回...示例 (JavaScript):
If your regular expressions support negative lookbehinds:
Otherwise, you will need to match the character before the
/
as well:This matches either the start of a string (
^
), or (|
) anything other than a\
([^\\]
) as capture group #1()
. Then it matches the literal/
after. Whatever character was before the/
will be stored in the capture group$1
so you can put it back in if you are doing a replace....Example (JavaScript):
您可以使用它:
这称为负向后查找。
我使用 / 作为分隔符
You can use this :
This is called a negative lookbehind.
I used / as the delimiters