string str = Regex.Match(body, "期間.*?(年齢|スキル|単価|期間|場所)").Value;
StringBuilder sb = new StringBuilder();
Regex regex = new Regex("[ぁ-んァ-ヶ亜-熙0-9〇-九a-zA-Z\r\n]");
Match match = regex.Match(body);
while (match.Success)
{
sb.Append(match.Value);
match = match.NextMatch();
}
return sb.ToString();
静的メソッド
くり返し使用しないパターンならば、静的メソッドで実行するのが簡単です。
Match match = Regex.Match(text, "[0-9]+"); MatchCollection matches = Regex.Matches(text, "[0-9]+"); string str = Regex.Replace(text, "[0-9]+", "A");
なおこれらは、次のように生成したオブジェクトからメソッドを呼び出すことと同義です。
Match match = new Regex("[0-9]+").Match(text);
MatchCollection matches = new Regex("[0-9]+").Matches(text);
string str = new Regex("[0-9]+").Replace(text, "A");
本文介绍如何利用正则表达式进行文本匹配、替换及提取等操作,并提供了具体的代码实例,包括创建Regex对象和使用静态方法的方式。
1347

被折叠的 条评论
为什么被折叠?



