C# 函数的作用是
这些标点符号后面的单词必须大写(注意,使用时,标点符号两侧可能有空格或特殊字符): 破折号(-),斜杠(/),冒号(:),句号(,),问号(?),感叹号 点(!)、省略号(…或…)(它们是不同的) 我有点陷入这个谜题,因为我试图在搜索中寻找所有特殊的正则表达式字符。我相信我可以使用Regex.Escape,尽管在这种情况下我现在无法让它为我工作 要更改为的起始字符串的几个示例可能是:C# 函数的作用是,c#,.net,regex,C#,.net,Regex,这些标点符号后面的单词必须大写(注意,使用时,标点符号两侧可能有空格或特殊字符): 破折号(-),斜杠(/),冒号(:),句号(,),问号(?),感叹号 点(!)、省略号(…或…)(它们是不同的) 我有点陷入这个谜题,因为我试图在搜索中寻找所有特殊的正则表达式字符。我相信我可以使用Regex.Escape,尽管在这种情况下我现在无法让它为我工作 要更改为的起始字符串的几个示例可能是: Change this: This is a dash - example To this: This is a
Change this:
This is a dash - example
To this:
This is a dash - Example <--capitalize "Example" with Regex
This is another dash -example
This is another dash -Example
This is an ellipsis ... example
This is an ellipsis ... Example
This is another ellipsis …example
This is another ellipsis …Example
This is a slash / example
This is a slash / Example
This is a question mark ? example
This is a question mark ? Example
更改此选项:
这是一个破折号示例
为此:
这是一个破折号示例您不需要迭代标点符号列表,而只需在单个正则表达式中添加一个字符集:
(?:[/:?!…-]|\.\.\.)\s*([a-z])
要将其与Regex.Replace()一起使用,请执行以下操作:
Regex解释说:
(?: # non-capture set
[/:?!…-] # match any of these characters
| \.\.\. # *or* match three `.` characters in a row
)
\s* # allow any whitespace between matched character and letter
([a-z]) # match, and capture, a single lowercase character
您不需要遍历标点符号列表,只需在单个正则表达式中添加一个字符集即可:
(?:[/:?!…-]|\.\.\.)\s*([a-z])
要将其与Regex.Replace()一起使用,请执行以下操作:
Regex解释说:
(?: # non-capture set
[/:?!…-] # match any of these characters
| \.\.\. # *or* match three `.` characters in a row
)
\s* # allow any whitespace between matched character and letter
([a-z]) # match, and capture, a single lowercase character
也许这对你有用:
var phrase = "This is another dash ... example";
var rx = new System.Text.RegularExpressions.Regex(@"(?<=[\-./:?!]) *\w");
var newString = rx.Replace(phrase, new System.Text.RegularExpressions.MatchEvaluator(m => m.Value.ToUpperInvariant()));
var phrase=“这是另一个破折号……示例”;
var rx=new System.Text.RegularExpressions.Regex(@“(?也许这对您有用:
var phrase = "This is another dash ... example";
var rx = new System.Text.RegularExpressions.Regex(@"(?<=[\-./:?!]) *\w");
var newString = rx.Replace(phrase, new System.Text.RegularExpressions.MatchEvaluator(m => m.Value.ToUpperInvariant()));
var phrase=“这是另一个破折号……示例”;
var rx=new System.Text.RegularExpressions.Regex(@)(?请显示您的代码。要大写,您需要Regex.Replace()的版本方法,其中它有一个替换回调。花几个小时阅读本教程:有些地方很难理解,但详细介绍了正则表达式引擎对模式的实际操作。为什么要使用正则表达式?这项任务可以通过一个简单的字符串来完成。Replace()我添加了我的示例代码。@你可能在那里找到了什么。很好。你能详细说明一下吗?我当然知道我要找的字符是什么。但我不知道它们后面是否有空格,我也不知道后面的单词是什么,但我知道我想大写这个单词。请显示你的代码。要大写,你需要我们需要具有替换回调的Regex.Replace()方法的版本。花几个小时阅读本教程:有些地方很难理解,但详细介绍了Regex引擎对模式的实际操作。为什么要使用Regex?这项任务可以通过一个简单的字符串来完成。Replace()我添加了我的示例代码。@你可能在那里找到了什么。很好。你能详细说明一下吗?我当然知道我要找的字符是什么。但是我不知道它们后面是否有空格,我也不知道后面的单词是什么,但我知道我想大写这个单词。