正则表达式难题,高手救命,新手帮忙。。。。。

phqde 2005-01-11 05:44:30

有一字符串,例如S="##,aaa bbb ccc,xxx yy zz,##,123 kk zz,##,zz hh kk,"
如何取得每个"##"之后的字符串,例如要取第一个第一个"##"之后的"aaa bbb ccc,xxx yy zz,##,"第二个"##"之后的"123 kk zz,"......
注:字符串S中类似"##,aaa bbb ccc,"的子字符串是很多的。

如何用正则表达式解决这个问题,望各位不吝赐教!
...全文
66 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
powbcom 2005-01-11
  • 打赏
  • 举报
回复
##[,a-z0-9A-Z]
hjqnet 2005-01-11
  • 打赏
  • 举报
回复
[Visual Basic]
Imports System
Imports Microsoft.VisualBasic
_

Public Class StringSplit2

Public Shared Sub Main()

Dim delimStr As String = " ,.:"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim words As String = "one two,three:four."
Dim split As String() = Nothing

Console.WriteLine("The delimiters are -{0}-", delimStr)
Dim x As Integer
For x = 1 To 5
split = words.Split(delimiter, x)
Console.WriteLine(ControlChars.Cr + "count = {0,2} ..............", x)
Dim s As String
For Each s In split
Console.WriteLine("-{0}-", s)
Next s
Next x
End Sub 'Main
End Class 'StringSplit2

[C#]
using System;

public class StringSplit2 {
public static void Main() {

string delimStr = " ,.:";
char [] delimiter = delimStr.ToCharArray();
string words = "one two,three:four.";
string [] split = null;

Console.WriteLine("The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words.Split(delimiter, x);
Console.WriteLine("\ncount = {0,2} ..............", x);
foreach (string s in split) {
Console.WriteLine("-{0}-", s);
}
}
}
}

[C++]
#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;

void main()
{

String* delimStr = S" ,.:";
Char delimiter[] = delimStr->ToCharArray();
String* words = S"one two,three:four.";
String* split[] = 0;

Console::WriteLine(S"The delimiters are -{0}-", delimStr);
for (int x = 1; x <= 5; x++) {
split = words->Split(delimiter, x);
Console::WriteLine(S"\ncount = {0, 2} ..............", __box(x));
IEnumerator* myEnum = split->GetEnumerator();
while (myEnum->MoveNext()) {
String* s = __try_cast<String*>(myEnum->Current);
Console::WriteLine(S"-{0}-", s);
}
}
}



///MSDN
hjqnet 2005-01-11
  • 打赏
  • 举报
回复
不明白,帮顶
listhome 2005-01-11
  • 打赏
  • 举报
回复
你是要解决问题,还是要学习正则??


为什么不用split?
wula0010 2005-01-11
  • 打赏
  • 举报
回复
up

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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