我想用C++正则表达式类来转
SELECT TableOne.ColumnOne, TableOne.@ColumnTwo, TableOne.ColumnThree FROM TableOne WHERE TableOne.@ColumnTwo ='abc'
进入
SELECT TableOne.ColumnOne, TableOne.ColumnThree FROM TableOne WHERE TableOne.ColumnTwo ='abc'
基本上,想做以下事情
(1)删除“FROM”之前的“TableOne.@ColumnTwo”之类的内容
(2)去掉“FROM”后面的“@”
有人可以给我一些启发吗?似乎没有直接的两个可以同时完成所有这些工作。
最佳答案
描述
正则表达式:^(.*?)TableOne[.]@ColumnTwo,\s+(.*?)[@](.*?)$
替换为:\1\2\3
例子
添加此 C# 示例以显示正则表达式的工作原理。
using System;
using System.Text.RegularExpressions;
namespace myapp
{
class Class1
{
static void Main(string[] args)
{
String sourcestring = "SELECT TableOne.ColumnOne, TableOne.@ColumnTwo, TableOne.ColumnThree FROM TableOne WHERE TableOne.@ColumnTwo ='abc'";
String matchpattern = @"^(.*?)TableOne[.]@ColumnTwo,\s+(.*?)[@](.*?)$";
String replacementpattern = @"\1\2\3";
Console.WriteLine(Regex.Replace(sourcestring,matchpattern,replacementpattern,RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline));
}
}
}
$sourcestring after replacement:
SELECT TableOne.ColumnOne, TableOne.ColumnThree FROM TableOne WHERE TableOne.ColumnTwo ='abc'
关于c++ - 使用 C++ 正则表达式一次性替换多个正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16894134/