急求正则表达式处理字符串

Anod 2013-11-20 04:59:16
fawe efaew fe,waf feaw,fe
few,ef few,ff fewfa,we few
fawe efaew fe,waf feaw,fe
few,ef few,ff fewfa,we few

上面实际上是个字符串,含有\t和\r\n

求个正则表达式,能把上面字符串中含有的 , 的项加上单引号,如将 few,ff 变为 'few,ff'
...全文
184 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
游离失所 2013-11-20
  • 打赏
  • 举报
回复
引用 6 楼 anodaniu 的回复:
[quote=引用 5 楼 lyj224170707 的回复:] [quote=引用 3 楼 anodaniu 的回复:] [quote=引用 1 楼 lyj224170707 的回复:]


string result = Regex.Replace("内容", @"([\w]*?,[\w]+)", "\"$1\"");
不符合啊 "Time:2013-11-11 10:54.41\r\nPoint\tZ\t\r\n{X=-147, Y=0}\t1660.9\t\r\n{X=-141.12, Y=0}\t1660.9\t\r\n{X=-135.24, Y=0}\t1660.9\t\r\n" 对这个字符串 希望匹配后能变成 "Time:2013-11-11 10:54.41 Point Z '{X=-147, Y=0} '1660.9 '{X=-141.12, Y=0} '1660.9 '{X=-135.24, Y=0} '1660.9" [/quote] string result = Regex.Replace("内容", @"{.*?,[^}]+?}", "'$0'");[/quote] 如果原数据没有{和}呢?[/quote]

string result = Regex.Replace("内容", @"\S+,[ ]\S+", "'$0'");
Anod 2013-11-20
  • 打赏
  • 举报
回复
引用 5 楼 lyj224170707 的回复:
[quote=引用 3 楼 anodaniu 的回复:] [quote=引用 1 楼 lyj224170707 的回复:]


string result = Regex.Replace("内容", @"([\w]*?,[\w]+)", "\"$1\"");
不符合啊 "Time:2013-11-11 10:54.41\r\nPoint\tZ\t\r\n{X=-147, Y=0}\t1660.9\t\r\n{X=-141.12, Y=0}\t1660.9\t\r\n{X=-135.24, Y=0}\t1660.9\t\r\n" 对这个字符串 希望匹配后能变成 "Time:2013-11-11 10:54.41 Point Z '{X=-147, Y=0} '1660.9 '{X=-141.12, Y=0} '1660.9 '{X=-135.24, Y=0} '1660.9" [/quote] string result = Regex.Replace("内容", @"{.*?,[^}]+?}", "'$0'");[/quote] 如果原数据没有{和}呢?
游离失所 2013-11-20
  • 打赏
  • 举报
回复
引用 3 楼 anodaniu 的回复:
[quote=引用 1 楼 lyj224170707 的回复:]


string result = Regex.Replace("内容", @"([\w]*?,[\w]+)", "\"$1\"");
不符合啊 "Time:2013-11-11 10:54.41\r\nPoint\tZ\t\r\n{X=-147, Y=0}\t1660.9\t\r\n{X=-141.12, Y=0}\t1660.9\t\r\n{X=-135.24, Y=0}\t1660.9\t\r\n" 对这个字符串 希望匹配后能变成 "Time:2013-11-11 10:54.41 Point Z '{X=-147, Y=0} '1660.9 '{X=-141.12, Y=0} '1660.9 '{X=-135.24, Y=0} '1660.9" [/quote] string result = Regex.Replace("内容", @"{.*?,[^}]+?}", "'$0'");
Anod 2013-11-20
  • 打赏
  • 举报
回复
引用 2 楼 q107770540 的回复:
str=Regex.Replace(str,@"\w+,\w+","'$0'");
还是不行 我是想把一个字符串 "Time:2013-11-11 10:54.41\r\nPoint\tZ\t\r\n{X=-147, Y=0}\t1660.9\t\r\n{X=-141.12, Y=0}\t1660.9\t\r\n{X=-135.24, Y=0}\t1660.9\t\r\n" 写到CSV文件里头,这样显示唉..: Time 2013-11-11 10:54.41 Point Z {X=-147, Y=0} 1660.9 {X=-141.12, Y=0} 1660.9 {X=-135.24, Y=0} 1660.9
Anod 2013-11-20
  • 打赏
  • 举报
回复
引用 1 楼 lyj224170707 的回复:


string result = Regex.Replace("内容", @"([\w]*?,[\w]+)", "\"$1\"");
不符合啊 "Time:2013-11-11 10:54.41\r\nPoint\tZ\t\r\n{X=-147, Y=0}\t1660.9\t\r\n{X=-141.12, Y=0}\t1660.9\t\r\n{X=-135.24, Y=0}\t1660.9\t\r\n" 对这个字符串 希望匹配后能变成 "Time:2013-11-11 10:54.41 Point Z '{X=-147, Y=0} '1660.9 '{X=-141.12, Y=0} '1660.9 '{X=-135.24, Y=0} '1660.9"
q107770540 2013-11-20
  • 打赏
  • 举报
回复
str=Regex.Replace(str,@"\w+,\w+","'$0'");
游离失所 2013-11-20
  • 打赏
  • 举报
回复


string result = Regex.Replace("内容", @"([\w]*?,[\w]+)", "\"$1\"");

110,539

社区成员

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

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

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