I want to check a string is matched so I will do some business logics with it.
The pattern is very simple.
If it matches 100% text but different number so it’s a match.
Example:
Pattern: "xxx is a large number" which xxx must be a integer number (not null, not empty, not text, not double number)
- "123 is a large number" => match
- "444444 is a large number" => match
- "is a large number" => not match
- "123 is not a large number" => not match
- "Test is a large number" => not match
My code:
var pattern = "^[0-9]+$ is a large number";
var testText = "123 is a large number";
var match = Regex.Match(testText, pattern, RegexOptions.IgnoreCase);
if (match.Success)
{
//do some business logics
}
This is the Regex I try but doesn’t work:
"^[0-9]+$ is a large number"
Thank you.
>Solution :
^(\d)+ is a large number$
-
^for the start of the string -
\d+for a digit, 1 or more times -
is a large number$for the rest of the string (and $ to signify the end)