Question: What's the simplest way how to test if given Regex
matches whole string ?
An example:
E.g. given Regex re = new Regex(".");
I want to test if given input string has only one character using this Regex re
. How do I do that ?
In other words: I'm looking for method of class Regex
that works similar to method matches()
in class Matcher
in Java ("Attempts to match the entire region against the pattern.").
Edit: This question is not about getting length of some string
. The question is how to match whole strings with regular exprestions. The example used here is only for demonstration purposes (normally everybody would check the Length
property to recognise one character strings).