|
マッチするかどうか確認する。 |
using System.Text.RegularExpressions;
Regex regex = new System.Text.RegularExpressions.Regex("ここに正規表現");
if ( regex.IsMatch("テストする文字列"))
マッチ!
MatchCollection matchCol = regex.Matches(this.tbInput.Text);
for(int i = 0; i < matchCol.Count; i++)
{
matchCol[i].Value);
} |
|
マッチする文字列を切り出す。 |
using System.Text.RegularExpressions;
Regex regex = new System.Text.RegularExpressions.Regex("ここに正規表現");
MatchCollection matchCol = regex.Matches("テストする文字列");
for(int i = 0; i < matchCol.Count; i++)
{
xxx = matchCol[i].Value);
}
// あるいは
foreach (Match match in matchCol)
{
xxx = match
} |
|
マッチする文字列を置換する。 |
using System.Text.RegularExpressions;
Regex regex = new System.Text.RegularExpressions.Regex("ここに正規表現");
string replacedString = regex.Replace("置換される文字列", "置換する文字列"); |