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 AZ || az 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
您想要的表达式是: /^([A-Za-z]+)/
use this regular expression (?i)^[az]+
Match match = Regex.Match(stringInput, @"(?i)^[a-z]+");
(?i)
- ignore case
^
- begin of string
[az]
- any latin letter
[az ]
- any latin letter or space
+
- 1 or more previos symbol
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.