Строка, которую мы получаем в нашем документе:

18.1Commitment fee
(a)The Parent shall pay to the Agent a fee in the Base Currency computed at the rate of:
(i)35 per cent. of the Margin per annum on that Commitment under Facility A for the Availability Period applicable to Facility A;
(ii)40 per cent. of the Margin per annum on that Commitment under Facility B for the Availability Period applicable to Facility B;

Ни в одном из них нет места (например ...) - ожидаемый результат ниже:

18.1 Commitment fee
(a) The Parent shall pay......
(i) 35 per cent of the margin....
(ii) 40 per cent of the margin....

Как добавить вид case if number, затем добавить пробел ... if (a) затем добавить пробел, если числа вроде (i) добавить пробел

Ниже - Regex.Replace (s, @ "^ (\ d + (?:. \ D {1,2})?) (?! [\ D \ s]) (. *)", "$ 1 $ 2") работает по номеру - предоставлено Wiktor Stribiew

0
user3657339 12 Дек 2018 в 17:27

1 ответ

Лучший ответ

Пытаться:

Regex.Replace(s, @"^(\([ivxcdlm]+\)|\([a-z]+\)|\d+\.?\d*)(.*)", "$1 $2", RegexOptions.IgnoreCase)

Детали регулярного выражения:

"^"                    Assert position at the beginning of a line (at beginning of the string or after a line break character) (line feed)
"("                    Match the regex below and capture its match into backreference number 1
                       Match this alternative (attempting the next alternative only if this one fails)
      "\("             Match the character “(” literally
      "[ivxcdlm]"      Match a single character from the list “ivxcdlm” (case insensitive)
         "+"           Between one and unlimited times, as many times as possible, giving back as needed (greedy)
      "\)"             Match the character “)” literally
   "|" 
                       Or match this alternative (attempting the next alternative only if this one fails)
      "\("             Match the character “(” literally
      "[a-z]"          Match a single character in the range between “a” and “z” (case insensitive)
         "+"           Between one and unlimited times, as many times as possible, giving back as needed (greedy)
      "\)"             Match the character “)” literally
   "|" 
                       Or match this alternative (the entire group fails if this one fails to match)
      "\d"             Match a single character that is a “digit” (any decimal number in any Unicode script)
         "+"           Between one and unlimited times, as many times as possible, giving back as needed (greedy)
      "\."             Match the character “.” literally
         "?"           Between zero and one times, as many times as possible, giving back as needed (greedy)
      "\d"             Match a single character that is a “digit” (any decimal number in any Unicode script)
         "*"           Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
")" 
"("                    Match the regex below and capture its match into backreference number 2
   "."                 Match any single character that is NOT a line break character (line feed)
      "*"              Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
")"  
0
Theo 12 Дек 2018 в 15:20