简体   繁体   English

在CDO.Message中使用RegEx与经典ASP

[英]Using RegEx in CDO.Message with Classic ASP

I'm working with the CDO.Message object in ASP VB, and I'm attempting to utilize VB Regular Expressions to process my form field (textarea) text before it's sent as a (non-HTML) email. 我正在使用ASP VB中的CDO.Message对象,并且尝试使用VB正则表达式处理表单字段(文本区域)文本,然后再将其作为(非HTML)电子邮件发送。

What I'm trying to do is to filter out any \\r or \\n (or combination) that occur without a preceding period. 我正在尝试做的是过滤掉没有前一个周期而出现的任何\\ r或\\ n(或组合)。 However, none of the Regular Expressions is of effect in the text in the email, although I've tested the code in an online Regex tester, and it worked fine. 但是,尽管我已经在在线Regex测试器中测试过代码,但正则表达式在电子邮件中的文本中均无效。

However, I can add chr(13) in the strings, and it shows in the email. 但是,我可以在字符串中添加chr(13),它会显示在电子邮件中。

I would prefer to not use HTML, if possible. 如果可能的话,我宁愿不使用HTML。 Would anyone have any suggestions as to why the Regex is not working? 关于正则表达式为什么不起作用,有人会提出任何建议吗?
Thanks 谢谢

Here's the regex below: 这是下面的正则表达式:

<%strGoals = Request.Form("Goals")
                        Set regEx = New RegExp
                        regEx.Global = True
                        regEx.IgnoreCase = True
                        regEx.Pattern = "(([^\.])(\r\n|\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"-->

Here is the code for 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它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM