如何将整个字符串与正则表达式匹配? [英] How do I match an entire string with a regex?

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

问题描述

我需要一个正则表达式,仅在整个字符串与我的查询匹配的地方找到匹配项。

I need a regex that will only find matches where the entire string matches my query.

例如,如果我搜索名称为 Red October的电影我只想匹配该确切标题(不区分大小写),而不匹配 The Hunt For Red October之类的标题。不太确定我知道该怎么做。有人知道吗?

For instance if I do a search for movies with the name "Red October" I only want to match on that exact title (case insensitive) but not match titles like "The Hunt For Red October". Not quite sure I know how to do this. Anyone know?

谢谢!

推荐答案

尝试以下正则表达式:

^Red October$

默认情况下,正则表达式区分大小写。 ^ 标记匹配文本的开始, $ 结束。

By default, regular expressions are case sensitive. The ^ marks the start of the matching text and $ the end.

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

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