简体   繁体   English

正则表达式分割字母

[英]Regular expression to split on letters

Using .net, what is a regular expression to split on, pulling out groups of letters? 使用.net,什么是正则表达式拆分,拉出字母组?

I tried @"[a-zA-Z]*", then regex.Split... as an example, but I'm totally lost. 我试过@“[a-zA-Z] *”,然后是regex.Split ......作为一个例子,但我完全迷失了。

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 . 实际上,如果您想要这些字母本身,请不要使用Regex.Split ,请使用Regex.MatchRegex.Matches The Split version will capture what's between the strings of letters. Split版本将捕获字母串之间的内容。

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 . 不完全是你要求的,但是,如果你已经知道可能会分开单词的那些字符,你可以简单地使用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(*" 当然,只有你有一些特定的字符分隔单词,如空格或逗号,如"word,word.word word"但如果你想在一堆中间拾取字母组,则不会其他的东西,比如"lk234lkv234.2@#$dfff(*"

I know I'm going a bit away from the original question, but still you might find this useful 我知道我离原始问题有点远,但你仍然觉得这很有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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