Reputation: 1193
Hi guys I have a string for example...
"Afds 1.2 45002"
What I wanted to do using regex is to start from the left, return characters A-Z || a-z until an unmatached is encountered.
So in the example above I wanted to return "Afds".
Another example
"BCAD 2.11 45099 GHJ"
In this case I just want "BCAD".
Thanks
Upvotes: 1
Views: 17248
Reputation: 13450
use this regular expression (?i)^[a-z]+
Match match = Regex.Match(stringInput, @"(?i)^[a-z]+");
(?i)
- ignore case
^
- begin of string
[a-z]
- any latin letter
[a-z ]
- any latin letter or space
+
- 1 or more previos symbol
Upvotes: 6
Reputation: 25619
string sInput = "Afds 1.2 45002";
Match match = Regex.Match(sInput, @"^[A-Za-z]+",
RegexOptions.None);
// Here we check the Match instance.
if (match.Success)
{
// Finally, we get the Group value and display it.
string key = match.Groups[1].Value;
Console.WriteLine(key);
}
Upvotes: 0