简体   繁体   English

需要C#Regex.replace模式

[英]C# Regex.replace Pattern needed

Usually I make my Regex patterns by myself, but I can't figure this one out: 通常,我自己制作正则Regex模式,但我无法弄清楚这一点:
I need a Regex.Replace that replaces "'Number'/'Number'" to "'Number'von'Number'". 我需要一个Regex.Replace ,将“'Number'/'Number'“替换为”'Number'von'Number'“。

Example: "2/5" schould become "2von5". 示例:“ 2/5”应该变成“ 2von5”。

The problem is that I can't just replace "/" to "von" because there are other "/" that are needed. 问题是我不能仅将“ /”替换为“ von”,因为还需要其他“ /”。

You can replace (?<=\\d)/(?=\\d) with von , using lookaround . 您可以使用环顾四周(?<=\\d)/(?=\\d)替换为von

Another option is to replace (\\d)/(\\d) with $1von$2 (though that would fail on 1/2/3 ). 另一种选择是将(\\d)/(\\d)替换$1von$2 (尽管在1/2/3失败)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM