Regex为asp.net中的字符串添加空间



我们在文档中得到的字符串:

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....

如何添加排序大小写如果数字,然后添加空格。。。如果(a(然后加空格,如果像(i(这样的数字加空格

下面-Regex.Replace(s,@"^(\d+(?:.\d{1,2}(?((?![\d\s]((.*(","$1$2"(在数字上工作-由Wiktor Stribiżew 提供

尝试:

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

Regex详细信息:

"^"                    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)
")"  

最新更新