我想开发一个简单的函数来替换sql语句中的fields子句
像这样的东西
replaceFields("select * from x", "f1")
// should return "select f1 from x"
replaceFields("select top 10 * FROM x", "f1")
// should return "select top 10 f1 FROM x"
replaceFields("select top 10 f3, f4 FROM x", "f1, f2")
// should return "select top 10 f1, f2 FROM x"
我知道这应该很简单,但我尝试了几个正则表达式,但我似乎找不到它
"select * from".replaceFirst("""select (\w+) from""", "count(*)")
// returns "select * from"
"select * from".replaceFirst("""select(\b(.*))\bfrom""", "count(*)")
// returns "count(*)"
但它没有用......