【www.gdgbn.com--安卓教程】

asp教程.net new regex正则a中标题方法

using system.text.regularexpressions; //正则

string strhtml = "

tags in this photo:

    belgium belgien urlaub holidays vakanties centerparcs 10 000 000 ";      textbox1.text = "" + strhtml + "";

          regex re = new regex("(?<= ]*/tags/[^>]*>).*?(?= )");

          if (re.ismatch(strhtml))
          {
              matchcollection mc = re.matches(strhtml);
              foreach (match ma in mc)
              {
                  for (int i = 0; i < ma.groups教程.count; i++)
                  {
                      textbox2.text += ma.groups[i].value + " ";
                  }
                  textbox2.text += "n";
              }
          }
          else
          {
              textbox2.text = "no";
          }

     

结果:

belgium
belgien
urlaub
holidays
vakanties
centerparcs
10 000 000


下面的示例使用正则表达式检查字符串中重复出现的词。 正则表达式 b(?<word>w+)s+(k<word>)b 可按下表中的方式解释。


模式
 description
 
b
 从单词边界开始匹配。
 
(?w+)
 匹配一个或多个单词字符(最多可到单词边界)。 将此捕获组命名为 word。
 
s+
 匹配一个或多个空白字符。
 
(k)
 匹配名为 word 的捕获组。
 
b
 与字边界匹配。
 
如果系统的当前区域性为 en-us,导致的正则表达式将是 ^w*[+-]? w? $? w?(d*.? d{2}?){1}$. 此正则表达式可按下表中所示进行解释。


模式
 description
 
^
 在字符串的开头处开始。
 
w*
 匹配零个或多个空白字符。
 
[+-]?
 匹配正号或负号的零个或一个匹配项。
 
w?
 匹配零个或一个空白字符。
 
$?
 匹配美元符号的零个或一个匹配项。
 
w?
 匹配零个或一个空白字符。
 
d*
 匹配零个或多个十进制数字。
 
.?
 匹配零个或一个小数点符号。
 
d{2}?
 匹配两位十进制数零次或一次。
 
(d*.?d{2}?){1}
 至少匹配一次由小数点符号分隔整数和小数的模式。
 
$
 匹配字符串的末尾部分
 

 

本文来源:http://www.gdgbn.com/shoujikaifa/28883/