RegEx在CDO.Message中的应用



我正在使用ASP VB中的CDO.Message对象,并试图在表单字段(文本区域)文本作为(非HTML)电子邮件发送之前,使用VB正则表达式来处理它。

我要做的是过滤掉没有前一个句点的任何\r\n或(或组合)。然而,没有一个正则表达式在电子邮件中的文本中有效,尽管我在Regex在线测试仪中测试了代码,它运行得很好。

但是,我可以在字符串中添加chr(13),它显示在电子邮件中。

如果可能的话,我宁愿不使用HTML。有人会对Regex为什么不起作用有什么建议吗
感谢

下面是正则表达式:

<%strGoals = Request.Form("Goals")
                        Set regEx = New RegExp
                        regEx.Global = True
                        regEx.IgnoreCase = True
                        regEx.Pattern = "(([^.])(rn|r|n)+)"

                        set matches = regEx.Execute(strGoals) 
                        If matches.Count > 0 Then
                        For Each Match in matches 
                        varGoalsResults = matches.item(0).submatches(0)
                        Response.write("<div style=""background-color:#f00;"">"&varGoalsResults&"</div>")
                        Next
                        Else
                        response.write("no matches")
                        End If
                        strGoals = Trim(regEx.Replace(strGoals, "$2"))
         strBody = strBody & "Goals: " & chr(13) & Request.Form("Goals") & chr(13) & chr(13)
%>
<!--#include virtual="SendEmail.asp"-->

以下是SendEmail.asp的代码:

<%
Set ObjMail = CreateObject("CDO.MESSAGE") 
ObjMail.From = strFrom
ObjMail.To = strTo
ObjMail.Cc = strCc
ObjMail.Subject = strSubject
'ObjMail.BodyPart.ContentMediaType = "multipart/alternative"
If strFormat = "HTML" Then
    strHTMLStart = "<html><head><style type=""text/css"">body {font-family:Arial, Helvetica, sans-serif;}</style></head><body>"
    strHTMLEnd = "</html></body>"
    ObjMail.HtmlBody = strHTMLStart & strBody & strHTMLEnd
Else
    ObjMail.TextBody = strBody
End If


ObjMail.Send 
Set ObjMail=nothing
%>

尝试使用regEx.Global = False应该可以工作。

相关内容

最新更新