小编Sae*_*adi的帖子

在c#中仅替换部分匹配的正则表达式

假设我有以下代码:

string input = "hello everyone, hullo anything";
string pattern = "h.llo [A-z]+";
string output = Regex.Replace(input,pattern,"world");
Run Code Online (Sandbox Code Playgroud)

(我已经尽力让它尽可能简单)

上面的代码输出是,"world, world"而我真正想要的是一种更改h.lloto之后的所有单词的方法world,并且我希望输出为"hello world, hullo world"

我一直在寻找一种方法来做到这一点,我进行了很多搜索并阅读了这篇文章:

使用正则表达式仅替换某些组

但我并没有从中得到太多,而且我不确定这是否正是我想要的。

有什么办法吗?

c# regex

4
推荐指数
1
解决办法
3445
查看次数

标签 统计

c# ×1

regex ×1