求一正则

loveyzy 2012-06-01 10:47:38
为了提取想要的数据,我弄了半天正则,没搞定,特来向大家求助:

[[["Please type the text or Web site address","请键入文字或网站地址","","Qǐng jiànrù wénzì huò wǎngzhàn dìzhǐ"]],,"zh-CN",,[["Please",[5],0,0,1000,0,1,0],["type",[6],1,0,1000,1,2,0],["the",[7],1,0,1000,2,3,0],["text or",[8],1,0,1000,3,5,0],["Web site address",[9],1,0,701,5,8,0]],[["请",5,[["Please",1000,0,0],["requested",0,0,0],["Requests the",0,0,0]],[[0,1]],"请键入文字或网站地址"],["键入",6,[["type",1000,1,0],["type the",0,1,0],["type a",0,1,0]],[[1,3]],""],["",7,[["the",1000,1,0]],,""],["文字 或",8,[["text or",1000,1,0],["words or",0,1,0],["the text or",0,1,0],["text or a",0,1,0]],[[3,6]],""],["网站 地址",9,[["Web site address",701,1,0],["website address",0,1,0],["site address",0,1,0],["website addresses",0,1,0],["Web site addresses",0,1,0]],[[6,10]],""]],,,[["zh-CN"]],8]

上述文字中,我想提取第一个引号内的文字,即Please type the text or Web site address
规则是第一个引号内的文字,请问大家有何良策?
...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-06-01
  • 打赏
  • 举报
回复
(?is)(['""])([^""']*)\1
还是用序列化好点
ycproc 2012-06-01
  • 打赏
  • 举报
回复


从你的数据看 是有规律的
可以用 Dictionary 序列化 提取 效率高一些
q107770540 2012-06-01
  • 打赏
  • 举报
回复
Regex reg=new Regex(@"(?s)(['""])(.*?)\1");
reg.Match(yourstr).Groups[2].Value就是你想要的
ParanoidKing 2012-06-01
  • 打赏
  • 举报
回复

Regex reg = new Regex(@"\""[^\""]+\""");
MatchCollection m = reg.Matches(input);
string output = m[0].Value.Replace("\"","");
pmars 2012-06-01
  • 打赏
  • 举报
回复
(?<=^[^'""]*?(['""]))[^'""]*(?=\1)

稍微改了下一楼的正则,只匹配到第一个!
q107770540 2012-06-01
  • 打赏
  • 举报
回复
既然是只匹配第一个引号内的数据,那就只匹配一次即可:

(?<=")[^"]+(?=")
  • 打赏
  • 举报
回复

string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx

string pattern = @"(?<=[^'""]*?(['""]))[^'""]*(?=\1)";
tempStr = Regex.Match(tempStr, pattern).Value;//Please type the text or Web site address
loveyzy 2012-06-01
  • 打赏
  • 举报
回复
@fengyarongaa
用Dictionary 会快一些吗,没有正则快吧

111,126

社区成员

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

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

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