cscの作法 その58
2022 ワード
概要
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
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
以上。
Author And Source
この問題について(cscの作法 その58), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/1eb5f03103e44daf4975著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .