[英]Find and replace/remove two words from a string using regex c#
I'm trying to read scripts from various .sql files into a string and execute them in SQL server using c#. 我正在尝试将各种.sql文件中的脚本读取为字符串,然后使用c#在SQL Server中执行它们。 I want to remove the terms USE, GO etc. I succeeded removing one word at a time but cannot find the pattern to search for two or more words at the same time.
我想删除术语USE,GO等。我一次成功删除了一个单词,但找不到同时搜索两个或多个单词的模式。
so far, 至今,
string pattern = @"\bUSE*\b";
string script = Regex.Replace(script, pattern, "");
How to add other search terms to the pattern? 如何在模式中添加其他搜索词? i tried msdn docs and previous questions but cannot find what i need.
我尝试了msdn docs和以前的问题,但找不到我需要的东西。 Any help is greatly appreciated.
任何帮助是极大的赞赏。
您可以在关键字中使用管道。
string pattern = @"\b(USE|GO|MORE|FEW_MORE|AND_SO_ON)\b";
I'm a little rusty, but have you tried 我有点生锈,但是你尝试过
string pattern = @"\bUSE*\b|\bGO*\b"
?? ??
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.