正则表达式查找和替换 [英] Regular Expression Find and replace
本文介绍了正则表达式查找和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我正在使用正则表达式替换/,例如在字符串1/2中,并将一部分更改为xml示例frac12,但我想要所有分数这是我到目前为止所拥有的...
Hi there i'm using regular expressions to replace "/" eg in string 1/2 and change into a fraction into xml example frac12 but i want all the fractions this is what i have so far...
public static string ChecknReplace(string ingredientsText)
{
string pattern = @"(\d{1}\\\d{1})";
string[] fractions = {"/"};
var matches = Regex.Matches(pattern, ingredientsText);
foreach(Match match in matches)
{
}
}
推荐答案
尝试:
Try:
Regex regex = new Regex(@"(\d+)/(\d+)");
string result = regex.Replace(InputText,"frac
1
2);
2 ");
这篇关于正则表达式查找和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文