正则表达式求助

moonlight007 2006-05-11 10:11:03
&BILLHEAD6025|20060509|20060509
13700000000|602502|20060511|1500|1
......
&BILLTAIL6025|16
&OUTHEAD6025|20060509|20060509
139000000|602507|20060509|5
......
&OUTTAIL6025|2
我有一段这样的内容,现在需要分开提取BILL项中内容和OUT项中的内容.BILL、OUT标签行的数字是会变动的,提取内容时不需要标签行内容.应该怎样取.在线等待........
...全文
130 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
linuxyf 2006-05-12
  • 打赏
  • 举报
回复
(?<=BILL.*)[\S\s]*(?=BILL.*)
(?<=OUT.*)[\S\s]*(?=OUT.*)
wxdl1981 2006-05-11
  • 打赏
  • 举报
回复
StringCollection GetLabels(string text)
{
string s = "&(BILL|OUT)(?<Label>[^&]*)";
StringCollection lables = new StringCollection();

MatchCollection matches = Regex.Matches(text, s);

foreach(Match match in matches)
{
lables.Add(match.Group("Label").Text);
}
return labels;
}
yurow 2006-05-11
  • 打赏
  • 举报
回复
中午吃饭,下午帮你试下吧
yurow 2006-05-11
  • 打赏
  • 举报
回复
[\&BILL|\&OUT][a-zA-Z]{4}(?<mytag>(\d+|\d*)*)
clcxr 2006-05-11
  • 打赏
  • 举报
回复
获得某个字符串在另个字符串第一次出现时前面所有字符
public static string GetFirstStr(string strOriginal,string strSymbol)
{
int strPlace=strOriginal.IndexOf(strSymbol);
if (strPlace!=-1)
strOriginal=strOriginal.Substring(0,strPlace);
return strOriginal;
}
用这个一项一项拆
moonlight007 2006-05-11
  • 打赏
  • 举报
回复
不可以的
lwjvince 2006-05-11
  • 打赏
  • 举报
回复
可以直接以| 为分界点 用substring来截取
yurow 2006-05-11
  • 打赏
  • 举报
回复
测试数据:
&BILLHEAD6025|20060509|20060509
13700000000|602502|20060511|1500|1


&BILLTAIL6025|16

&OUTHEAD6025|20060509|20060509
139000000|602507|20060509|5

&OUTTAIL6025|2

表达式:[\&BILL][A-Z]{4}(?<mytag>[\d+\|\d*\n*\r*]*)

结果:
6025|20060509|20060509
13700000000|602502|20060511|1500|1

6025|16

表达式:[\&OUT][A-Z]{4}(?<mytag>[\d+\|\d*\n*\r*]*)

结果:
6025|20060509|20060509
139000000|602507|20060509|5

6025|2

测试器
http://birdshover.cnblogs.com/archive/2006/05/10/396844.html

110,567

社区成员

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

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

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