c#提取字符串中第一个非英文字母前的字符

请各位帮忙

c#提取字符串中第一个非英文字母前的字符

如,abc-333-def

gh-555-jkl

你这话就有歧义
到底是提取第一个字符,还是第一个字母前的所有字符,第一是修饰字母的还是修饰字符的
不要仅放出待测数据,你想提取的内容也一并放出,才好让别人理解你到底要干什么

你的意思是提取非英文字符串前的字符?


string str = "abc-333-def";
string res = Regex.Match(str,"^([a-zA-Z]*).*$").Groups[1].ToString();

对每个字符判断,判断条件是否是大写的英文字母或者是小写的英文字母,满足条件继续,不满足返回当前下标-1(我的笨方法,手动滑稽)

Regex.Match(s, @"(.)[^a-z0-9]").Groups[1].ToString()

```c#


```


  public void getStr()
        {
            string str = "abc-333-def";           
            for (int counter = 0; counter < str.Length; counter++)
            {               
                bool result = Regex.IsMatch(str[counter].ToString(), @"^[A-Za-z]+$");
                if (!result)
                {   if(counter!=0)
                    {
                        Console.WriteLine(str[counter - 1]);
                    }                    
                    break;
                }
                else
                {
                    continue;
                }
            }            

        }

正则就行,楼上都给出了