Excel
由于您在 excel 中执行此操作,因此您可能需要考虑使用此公式
=MID(B1,SEARCH("<amount>",B1)+8,SEARCH("</amount>",B1)-(SEARCH("<amount>",B1) + 8))
B1
= 输入字符串
+8
补偿字符串的宽度<amount>
- C列显示使用的公式
正则表达式
如果您使用 VBA 和正则表达式执行此操作,则可以使用正则表达式:<(amount)\b[^>]*>([^<]*)<\/\1>
此 VB.net 示例仅用于显示正则表达式如何使用金额标签中的每个美元值填充组 3。
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sourcestring as String = "<field1>05/14/2013</field1><amount>3,100,000.00</amount><field3>026002561</field3>
<field1>05/14/2013</field1><amount>4,444,444.00</amount><field3>026002561</field3>"
Dim re As Regex = New Regex("<(amount)\b[^>]*>([^<]*)<\/\1>",RegexOptions.IgnoreCase OR RegexOptions.Multiline OR RegexOptions.Singleline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module
$matches Array:
(
[0] => Array
(
[0] => <amount>3,100,000.00</amount>
[1] => <amount>4,444,444.00</amount>
)
[1] => Array
(
[0] => amount
[1] => amount
)
[2] => Array
(
[0] => 3,100,000.00
[1] => 4,444,444.00
)
)