regex - How to replace sentences between 2 key words in an email? -
regex - How to replace sentences between 2 key words in an email? -
i had before asked question @ link on regex how delete sentences between 2 words before forwarding email?
i went , tried suggestion , made observations. below script trying to:
change email subject insert new line email body locate , replace sentences in email body between words "impact" , "corrective action" forward emailset fwdmsg = item.forward fwdmsg  dim regex new regexp    regex      .global = false      .multiline = true      .ignorecase = false      .pattern = strpattern     end      dim newbody string     dim source string     source = fwdmsg.htmlbody      dim replacestr string     replacestr = "$1\n\nplease  phone call me number\n\n$2"     strpattern = "^(impact:)\s*(?:(?!^(?:impact:|correction[^\s\n]+action))[\s\s])*^(correction[^\s\n]+action)"     newbody = regex.replace(source, replacestr)     fwdmsg.htmlbody = newbody      newline = "dear users,please note   info affected incident below , corrected. please email  more information."      fwdmsg.htmlbody = newline & fwdmsg.htmlbody      fwdmsg.recipients.add "xx.com.sg"     fwdmsg.subject = "incident" & format$(now, " dd-mm-yyyy hh.mmam/pm")    somehow, noticed few things when wrote script on outlook.
the code unable locate sentences between words impact , correction action , hence sentences not removed. thereplacestr line gets displayed on email not replacing sentences between words impact , correction action.   any ideas?
looks me didn't initialize strpattern before using it: 
with regex  .global = false  .multiline = true  .ignorecase = false  .pattern = strpattern ' empty string "" end    at point,  nil has been assigned strpattern, contains  nil empty string "". regex literally looking first occurrence of "", presume finds right @ start of e-mail. not want. 
to  prepare this, move line in assign value strpattern appears before place  utilize variable, e.g.
strpattern = "^(impact:)\s*(?:(?!^(?:impact:|correction[^\s\n]+action))[\s\s])*^(correction[^\s\n]+action)" regex  .global = false  .multiline = true  .ignorecase = false  .pattern = strpattern ' contains you're looking for. end    or, rid of useless temp variable altogether! don't see using anywhere else, why not inline it.
with regex  .global = false  .multiline = true  .ignorecase = false  .pattern = "^(impact:)\s*(?:(?!^(?:impact:|correction[^\s\n]+action))[\s\s])*^(correction[^\s\n]+action)" end        regex vba email outlook outlook-vba 
 
  
Comments
Post a Comment