Micah Micah - 2 months ago 7
C# Question

How do I match an entire string with a regex?

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

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?

Thanks!

Answer

Try the following regular expression:

^Red October$

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