正则表达式匹配完整字符串 [英] RegEx to match full string

查看:45
本文介绍了正则表达式匹配完整字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 301 创建一个正则表达式来帮助我识别 url:site.com/abc/ 并重定向到 site.com/xyz/.我试过正则表达式为 ^abc/? 并且它工作正常,但问题是甚至像 site.com/123/sdas/abc/213 这样的 url 也被捕获.如何确保只有 /abc 与完整的字符串 url 匹配?

I am trying to create a regex for 301s that will help me identify the url: site.com/abc/ and redirect to site.com/xyz/. I've tried regex as ^abc/? and it works fine but the problem is even urls like site.com/123/sdas/abc/213 are getting caught. How can I ensure only /abc gets matched with the full string url?

推荐答案

使用行尾锚点 $:

^abc/$

这确保了精确的字符串 abc/ 将被匹配.

This ensures that the exact string abc/ will be matched.

这篇关于正则表达式匹配完整字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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