使用正则表达式提取字符串!

zwl850918 2009-02-25 04:01:11
helloworld:myname is tianya

MIME-Version: 1.0
Content-Type: Multipart/report;
report-type=delivery-status;

-----Content-Description: Delivery error report

我想使用正则表达式 c#提取:
MIME-Version: 1.0
Content-Type: Multipart/report;
report-type=delivery-status;

应该怎么写?
...全文
285 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
baiyunyinv 2009-02-25
  • 打赏
  • 举报
回复
((?<=helloworld:myname is tianya)[\s\S]+(?=-----))
zwl850918 2009-02-25
  • 打赏
  • 举报
回复
strText是动态改变的 不变只是
helloworld:myname is tianya 和-----Content-Description: Delivery error report 我取的就是动态改变的字符串


baiyunyinv 2009-02-25
  • 打赏
  • 举报
回复
是动态生成的话,试试
((?<=\r\n)[\s\S]+(?=-----))
baiyunyinv 2009-02-25
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string strText = "helloworld:myname is tianya\r\n\r\nMIME-Version: 1.0\r\nContent-Type: Multipart/report;\r\nreport-type=delivery-status;\r\n\r\n-----Content-Description: Delivery error report";
Console.WriteLine(strText);
Console.WriteLine("正则表达式匹配的结果如下:");
Console.WriteLine(Regex.Match(strText, @"(?<result>MIME-Version[\s\S]+(?=-----))").Groups[0].ToString()/*.Result("${result}")*/);
Console.ReadLine();
}
}
}

zwl850918 2009-02-25
  • 打赏
  • 举报
回复
好像不行...而且helloworld:myname is tianya 与-----Content-Description: Delivery error report 之间的字符串是动态的..
EveryCase 2009-02-25
  • 打赏
  • 举报
回复
顶~~~~~~~~~~
wuhq030710914 2009-02-25
  • 打赏
  • 举报
回复
MIME-Version[\s\S]+(?=---)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧