I require a regular expression which does following
This is what I tried:
string result = Regex.Replace(input,@"^[a-z]\s?[a-z0-9]\s?[^A-Z]","");
This is what should happen:
Sample input = "of !jgf area. The wealth of nation"
Required Output ="The Wealth of nation"
What should I do to improve/correct?
您可以像下面这样:
string result = Regex.Replace(input,@"^[^A-Z]*","");
This pattern will suffice.
^[^A-Z]+
It will replace all the characters that is not an upper case letter
By the way there is a much faster way without RegEx in C#.
int index=str.indexOfAny(new char[] { 'A', 'B', ..., 'Z'})
if(index!=-1){
str = str.Substring(index);
}
" ([A-Z]+.*)"
使用组,Gruops [1]是您想要的
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.