如何去除换行?
How to remove line feed?
此 Outlook 脚本 returns 所需日期但不删除换行符。
我想获取日期的字符串:
1_c Anruf/Meldung 上午(基准):04.Mai.2020
With Reg1
.Pattern = "1_c Anruf\/Meldung am \(Datum\)\s*[:]+\s*(.*)\s+\n"
.Global = False
End With
If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
End If
For Each M In M1
Debug.Print M.SubMatches(0)
With xExcelApp
Range("A5").Value = M.SubMatches(0)
End With
Next M
regex101 选择正确,但调试器始终显示类似“02.12.2020”的内容。 <- 不包含空格但包含换行符。
在 Excel 中,换行符也是可见的。尾随空格也不是问题,因为我可以使用 TRIM 但换行不允许它起作用。
您的正则表达式捕获了 CR 符号,您可以将 .
替换为 [^\r\n]
以避免此行为。
看来你想用
1_c Anruf/Meldung am \(Datum\)\s*:+\s*([^\r\n]*\S)
见regex demo。请注意,不必在 VBA 代码中对正斜杠进行转义。 详情:
1_c Anruf/Meldung am \(Datum\)
- 一个固定的 1_c Anruf/Meldung am (Datum)
字符串
\s*:+\s*
- 一个或多个冒号用零个或多个空格括起来
([^\r\n]*\S)
- 捕获第 1 组(使用 M.SubMatches(0)
访问)捕获零次或多次出现的除 CR 和 LF 字符之外的任何字符,然后是任何非空白字符。
此 Outlook 脚本 returns 所需日期但不删除换行符。
我想获取日期的字符串:
1_c Anruf/Meldung 上午(基准):04.Mai.2020
With Reg1
.Pattern = "1_c Anruf\/Meldung am \(Datum\)\s*[:]+\s*(.*)\s+\n"
.Global = False
End With
If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
End If
For Each M In M1
Debug.Print M.SubMatches(0)
With xExcelApp
Range("A5").Value = M.SubMatches(0)
End With
Next M
regex101 选择正确,但调试器始终显示类似“02.12.2020”的内容。 <- 不包含空格但包含换行符。
在 Excel 中,换行符也是可见的。尾随空格也不是问题,因为我可以使用 TRIM 但换行不允许它起作用。
您的正则表达式捕获了 CR 符号,您可以将 .
替换为 [^\r\n]
以避免此行为。
看来你想用
1_c Anruf/Meldung am \(Datum\)\s*:+\s*([^\r\n]*\S)
见regex demo。请注意,不必在 VBA 代码中对正斜杠进行转义。 详情:
1_c Anruf/Meldung am \(Datum\)
- 一个固定的1_c Anruf/Meldung am (Datum)
字符串\s*:+\s*
- 一个或多个冒号用零个或多个空格括起来([^\r\n]*\S)
- 捕获第 1 组(使用M.SubMatches(0)
访问)捕获零次或多次出现的除 CR 和 LF 字符之外的任何字符,然后是任何非空白字符。