关于正则表达式的一个问题

WindowsAzure 2008-02-02 01:03:35
一个字符串,如: abc defg(1,2,3,4)dfjdkfsl,把其中的(1,2,3,4)选出来的正则表达式请问是怎么样的啊?
...全文
186 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
luzeqiang 2008-02-14
  • 打赏
  • 举报
回复
什么意思???
amaodun 2008-02-14
  • 打赏
  • 举报
回复
问题的确没提清楚。

正则表达式的编写严重依赖使用场景,对情形了解越准确越好。

比如直接按楼主所述的话,pattern=@"(1,2,3,4)" 就满足了。
eyesinbook 2008-02-14
  • 打赏
  • 举报
回复
string.split('(')[1].split(')')[0]
  • 打赏
  • 举报
回复
\([\d ¦,]+?\)
wwlprince 2008-02-14
  • 打赏
  • 举报
回复
string   str1="   abc   defg(1,2,3,4)dfjdkfsl";
str1=Regex.Replace(str1,@"[^\((\d+,)*\d+\)]","");
Tensionli 2008-02-14
  • 打赏
  • 举报
回复
\((\d+,)*\d+\)匹配括号
sunray1301 2008-02-14
  • 打赏
  • 举报
回复
问题没有说明白 呵呵
Q_282898034 2008-02-02
  • 打赏
  • 举报
回复
楼主这问题究竟要问什么?
A 把所有英文字母和空格去掉?
B 保留括号和括号内的所有内容?
C 保留括号和括号内的数字、逗号?

假如括号内出现英文字母怎么办
lake_cx 2008-02-02
  • 打赏
  • 举报
回复
5楼正确的啊
harryheart 2008-02-02
  • 打赏
  • 举报
回复
楼上的都会匹配(1,2,,,,3)
Go 旅城通票 2008-02-02
  • 打赏
  • 举报
回复
string pattern=@"(\([^\)]*?\))";
harryheart 2008-02-02
  • 打赏
  • 举报
回复
\((\d+,)*\d+\)
xingtianzhang2008 2008-02-02
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace TSConsole
{
class Program
{
static void Main(string[] args)
{
string mystring = " abc defg(1,2,3,4)dfjdkfsl";
Regex Re = new Regex(@"\((.*?)\)");
Match M = Re.Match(mystring);
if (M.Success)
{
Regex Re2 = new Regex(@"(\d{1,})");
MatchCollection Mc=Re2.Matches(M.Value);
foreach(Match M2 in Mc)
{
Console.WriteLine(M2.Groups[1].Value);
}
}
else
{
Console.WriteLine("nothing ");
}
Console.ReadKey();
}
}
}
  • 打赏
  • 举报
回复
[(),\d]*
fancystyle 2008-02-02
  • 打赏
  • 举报
回复
\([\d|,]+?\)
fancystyle 2008-02-02
  • 打赏
  • 举报
回复
\(.+?\)

这样

110,539

社区成员

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

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

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