我想用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”之后的任何“@”
有人可以帮我一些光吗?似乎没有直接的两个人去做所有这些。答案 0 :(得分:0)
正则表达式:^(.*?)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'