简体   繁体   中英

Regular expression to split on letters

Using .net, what is a regular expression to split on, pulling out groups of letters?

I tried @"[a-zA-Z]*", then regex.Split... as an example, but I'm totally lost.

Thanks

The * doesn't require at least one character to match. Try

@"[a-zA-Z]+"

instead.

Actually, if you want the letters themselves, don't use Regex.Split , use Regex.Match or Regex.Matches . The Split version will capture what's between the strings of letters.

Not exactly what you asked for, but, just in case you already know the kind of caracters that might separate the words you could simply use String.Split .

Of course this is only if you there are a few specific characters separating the words, such as spaces or commas, like "word,word.word word" but not if you want to pick up groups of letters in the middle of a bunch of other stuff like in "lk234lkv234.2@#$dfff(*"

I know I'm going a bit away from the original question, but still you might find this useful

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM