我正在使用ASP中的CDO.Message对象,并且我试图利用VB正则表达式来处理表单字段(文本区)文本,然后将其作为(非超文本标记语言)电子邮件发送。
我正在尝试做的是过滤掉任何\r或\n (或组合),它们没有前面的句点。然而,这些正则表达式在电子邮件的文本中都没有效果,尽管我已经在一个在线Regex测试器中测试了代码,它工作得很好。
但是,我可以在字符串中添加chr(13),它会显示在电子邮件中。
如果可能的话,我不喜欢使用HTML。对于Regex不能工作的原因,有人有什么建议吗?
谢谢
下面是正则表达式:
<%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"-->以下是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
%>发布于 2014-09-09 02:47:33
试试regEx.Global = False,它应该可以工作。
https://stackoverflow.com/questions/25728445
复制相似问题