如何在UIPath中使用正则表达式匹配替换

问题描述

我有一个正则表达式来过滤数据

enter image description here

#Matches结果

 Homeowner's Insurance Premium ( 12 mo.) toAmerican Family  $893.00
 Insura
 Mortgage Insurance Premium (     mo.)
 Prepaid Interest ($5.99 per day from 10/02/2020 to 10/01/2020) -$5.99

使用上面的Matches活动中的每个循环,我要删除所有美元,例如$ 893.00,$ 5.99等 使用ff。正则表达式,但没有用。任何想法 ?谢谢。

(.*)\s\$\d[\d.]*([^\r\n]*)(?:\r?\n(?!\d+ )(.+))?
System.Text.RegularExpressions.Regex.Replace(item,"(.*)\s\$\d[\d.]*([^\r\n]*)(?:\r?\n(?!\d+ )(.+))?","")

解决方法

要删除字符串末尾的美元金额,您可以使用

Regex.Replace(item,@"\s*[+-]?\$\d*\.?\d+\s*$","")

确保在C#代码中使用 verbatim字符串文字 @"..."(虽然在VB.NET中不需要),才能使用单个{{1 }}作为正则表达式转义字符。

模式表示

  • \-超过0个空格
  • \s*-可选的[+-]?-
  • +-一个\$字符
  • $-0或更多数字
  • \d*-可选的\.?
  • .-1个以上数字
  • \d+-0个或多个空格
  • \s*-字符串的结尾。

请参见RegexStorm regex demo online(单击底部的 Context 标签以查看替换结果)。