简单的正则表达式 url 相关匹配帮助
采用以下 URI:
http:\/\/.*\.google\.com/search/results\.php*
我只是尝试匹配给定 URI 中两个字母数字字符之间的所有单正斜杠 ( / )。在上面的例子中,两个就在搜索和结果之前。你能指出我正确的方向吗?
编辑
目的是使用 Notepad++ 进行搜索和替换。
Take the following URI:
http:\/\/.*\.google\.com/search/results\.php*
I am simply trying to match all single forward slashes ( / ) between two alphanumeric characters in a given URI. In the case above, the two just before search and results. Could you point me in the right direction?
EDIT
The intention is to do search and replace using Notepad++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://..google.com/search/results.php
http://..google.com/search/results.php
不太确定你在那里做什么,因为你的“URI”似乎已经是一个正则表达式。
但要匹配嵌入在字母数字字符之间的斜杠 (
/
),您可以使用:正向后查找和先行查找确保斜杠确实位于两个字母数字字符之间。
在 Windows PowerShell 中测试:
ETA: 如果我理解正确的话,您想用
\/
替换嵌入在两个字母数字字符之间的斜杠来转义它们,对吧?然后将以下内容替换
为
应该可以。这不仅仅捕获斜杠(如上面的方法;由于 Notepad++ 的限制),因此我们还必须重新插入周围的字符。
但是,您可能无论如何都想搜索未转义的斜杠。因此,我认为替换
为
更有意义。这将搜索前面没有反斜杠的斜杠。
Not really sure what you're doing there, as your “URI” is seemingly already a regex.
But to match a slash (
/
) embedded between alphanumeric characters, you can use:A positive lookbehind and lookahead make sure that the slash is indeed between two alphanumeric characters.
Test in Windows PowerShell:
ETA: If I understood you correctly you want to replace slashes embedded between two alphanumeric characters by
\/
to escape them, right?Then replacing the following
by
should work. This doesn't capture the slash only (as above method; due to limitations of Notepad++) therefore we have to reinsert the surrounding characters as well.
However, you probably want to search for unescaped slashes anyway. So replacing
by
would make more sense, I think. This searches for a slash that is not preceded by a backslash.