C#正则表达式替换文本段落中的短语

时间:2017-04-12 07:55:37

标签: c# regex

我使用C#File.ReadAllText()从文件中读取一段文本。说这是我的输出:

See [a car] is a wheeled, self-powered motor vehicle used for transportation 
and a product of the automotive industry. 

Most definitions of the term specify that [a car] is designed to run 
primarily on roads, to have seating for one to eight people, to typically 
have four wheels with tyres

我希望匹配并替换短语“a car”,但仅使用“test string”替换第二次出现。添加了Brackets []以便于阅读,但它们并不存在于文件文本中。我在StackOverflow上看到的正则表达式只替换了没有换行符的字符串中的字符/单词。如何搜索整段文本并在第二次出现短语时进行正则表达式替换?

0 个答案:

没有答案