我使用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上看到的正则表达式只替换了没有换行符的字符串中的字符/单词。如何搜索整段文本并在第二次出现短语时进行正则表达式替换?