110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace FormExport
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string s = "<li > <span> <a href=\"http://www.360buy.com/electronic.html\" onclick=\"setWebBILinkCount('index_channel_ele')\" onfocus=\"this.blur()\">家用电器 </a> </span> </li>";
Regex rg = new Regex("<li > <span> <a .+>(\\w+) </a> </span> </li>");
bool b1 = Regex.IsMatch("asdf", ".*");
bool b = rg.IsMatch(s);
Match m = rg.Match(s);
string name = m.Groups[1].ToString();
}
}
}
//Regex 類在這個命名空間中哦
using System.Text.RegularExpressions;
string s = "<li > <span> <a href=\"http://www.360buy.com/electronic.html\" onclick=\"setWebBILinkCount('index_channel_ele')\" onfocus=\"this.blur()\">家用电器 </a> </span> </li>"
Regex rg = new Regex("<li > <span> <a .+>(\\w+) </a> </span> </li>");
bool b = rg.IsMatch(s);//我測試時,這裡返回true
Match m = rg.Match(s);
string name = m.Groups[1];//這裡取出的值就是你想要的值了,這裡在正則表達式中就是我用()括起來的那個地方的值
@"[\u4e00-\u9fa5\s]+"
@”[u4e00-u9fa5]+“