Updated at Feb 10
Field Diff
Corpus Text var expr = "(123/456) / 789/2 + 789)";456 / 999 /456)"; var// denomremove spaces expr = Regex.Match(expr,expr.Replace(" @"\/[0-9]*").Value.Trim('/');", ""); // split numbers into array var addendexprs = Regex.Match(expr, @"(?<=\+\s)\d+").Value;expr.Split('/'); exprvar curIndex = expr.Replace(denom,0; var $"NULLIF({denom},0)");result = string.Empty; foreach (var ex in exprs) expr{ var numberOnly = expr.Replace(addend,Regex.Match(ex, $"NULLIF({addend},0)"); @"\d+").Value;Console.WriteLine(expr); // get index of current number curIndex = expr.IndexOf(numberOnly, curIndex); // get index - 1, to check the operator var operatorIndex = curIndex - 1; if(operatorIndex - 1 < 0) { continue; } var operatorText = expr[operatorIndex].ToString(); if(operatorText == "/") { result += expr.Substring(0, curIndex) + string.Concat(" NULLIF(", numberOnly, ",0) "); Console.WriteLine(result); } } Console.WriteLine(result);
Updated at Feb 10
Field Diff
Regex \/[0-9][0-9]*\) p=(\d+)
Corpus Text (272/273)var expr = "(123/456) + 3789)"; var denom = Regex.Match(expr, @"\/[0-9]*").Value.Trim('/'); var addend = Regex.Match(expr, @"(?<=\+\s)\d+").Value; expr = expr.Replace(denom, $"NULLIF({denom},0)"); expr = expr.Replace(addend, $"NULLIF({addend},0)"); Console.WriteLine(expr);
Updated at Feb 09
Field Diff
Regex \/[1-9][0-9]*\)\/[0-9][0-9]*\)
Updated at Feb 09
Refiddle Do you know PHP, Perl, Python or Java? View the docs to see how you can help out

5e40e5f175622d2a10010000 Revisions

Created Feb 09 by anonymous.

Replay this Fiddle