cscの作法 その58


概要

cscの作法、調べてみた。
regexやってみた。

参考にしたページ

サンプルコード

using System;
using System.Text.RegularExpressions;

class reg2
{
	static void Main() {
		string s = @"
This is a test program.
you can download it from the following page.
http://www.xxx.yyy/bin/test.php
If you have any questions about this,
please contact us by sending e-mail to the following address.
[email protected]
";
		Console.Write(">対象\n");
		Console.Write(s);
		Console.Write("\n");
		Console.Write(">メールアドレス抽出\n");
		Regex email = new Regex(@"\w*@[\w\.]*");
		Console.Write("{0}\n", email.Match(s).Value);
		Console.Write(">URL 抽出\n");
		Regex http = new Regex(@"http://(?<domain>[\w\.]*)/(?<path>[\w\./]*)");
		Match m = http.Match(s);
		Console.Write("{0}\n", m.Value);
		Console.Write("domain: {0}   path: {1}\n", m.Groups["domain"].Value, m.Groups["path"].Value);
		Console.Write(">t の付く単語全部抜き出し\n");
		Regex wordIncludingT = new Regex(@"\w*[tT]\w*");
		for (m = wordIncludingT.Match(s); m.Success; m = m.NextMatch())
			Console.Write("{0}  ", m.Value);
		Console.Write("\n");
	}
}





実行結果


>対象

This is a test program.
you can download it from the following page.
http://www.xxx.yyy/bin/test.php
If you have any questions about this,
please contact us by sending e-mail to the following address.
[email protected]

>メールアドレス抽出
[email protected]
>URL 抽出
http://www.xxx.yyy/bin/test.php
domain: www.xxx.yyy   path: bin/test.php
>t の付く単語全部抜き出し
This  test  it  the  http  test  questions  about  this  contact  to  the  support

以上。