【发布时间】:2012-03-28 15:03:29
【问题描述】:
通常我自己制作Regex 模式,但我无法弄清楚这个:
我需要一个Regex.Replace 将“'Number'/'Number'”替换为“'Number'von'Number'”。
例如:“2/5”应该变成“2von5”。
问题是我不能只将“/”替换为“von”,因为还需要其他“/”。
【问题讨论】:
通常我自己制作Regex 模式,但我无法弄清楚这个:
我需要一个Regex.Replace 将“'Number'/'Number'”替换为“'Number'von'Number'”。
例如:“2/5”应该变成“2von5”。
问题是我不能只将“/”替换为“von”,因为还需要其他“/”。
【问题讨论】:
您可以使用lookaround 将(?<=\d)/(?=\d) 替换为von。
另一种选择是将(\d)/(\d) 替换为$1von$2(尽管在1/2/3 上会失败)。
【讨论】: