Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex Phrase search

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
US
I'm trying to do a replace using regex, and I'm horrible at writing the correct syntax. I want to replace the phrase
"Restricted Internal Use Only". There can be spaces or returns as the whitespace because it could land on multiple lines, and I'm searching for the string in the HTML body of an outlook messsage (pulled into a string), so there could be spaces or tags before or after the phrase...

Here is what I have right now...

Code:
Function StripText(ByVal theBody As String) As String
 Dim RegEx As Object
 Set RegEx = CreateObject("vbscript.regexp")
 With RegEx
  .Global = True
  .IgnoreCase = True
  .MultiLine = True
  .Pattern = "^(RESTRICTED\s+INTERNAL\s+USE\s+ONLY)$"
 End With
 StripText = RegEx.Replace(theBody, "--------------------")
 Set RegEx = Nothing
 
End Function

Does anyone have any thoughts on how to make this work?
 
Have you tried this ?
.Pattern = "RESTRICTED\s+INTERNAL\s+USE\s+ONLY"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Are you trying to eliminate it to bypass email security? If so, it might just be easier (and more conformant with corporate policy) to ask if an exemption can be made.
 
I did try this...

Code:
.Pattern = "RESTRICTED\s+INTERNAL\s+USE\s+ONLY"

and it didn't work...

I'm not bypassing any corporate rules in this situation. I'm already scrubbing the email of sensitive information using a regex pattern search for numbers. Once the numbers are removed, the next step in the process is to remove that line of text. I'm basically just turning a manual process into an automated process.

I can't figure out why it's not pulling this information out of the string. I've dumped the html string into a text file to get a good look at it... and this is what I'm getting...

<p class=MsoNormal style='text-autospace:none'><font size=2 face=""Courier New""><span
style='font-size:10.0pt;font-family:""Courier New""'>RESTRICTED - INTERNAL USE
ONLY<o:p></o:p></span></font></p>

I also tried to use substrings and that didn't work...

Code:
Function StripText(ByVal theBody As String) As String
 Dim RegEx As Object
 Set RegEx = CreateObject("vbscript.regexp")
 With RegEx
  .Global = True
  .IgnoreCase = True
  .MultiLine = True
  .Pattern = "(\D|^)(RESTRICTED\s+INTERNAL\s+USE\s+ONLY)(\D|$)"
 End With
 StripText = RegEx.Replace(theBody, "$1--------------------$3")
 Set RegEx = Nothing

End Function
 
I just answered my own question... it's always the little things isn't it... I forgot to accomodate the dash... (RESTRICTED - INTERNAL USE
ONLY)

Code:
.Pattern = "(\D|^)(RESTRICTED\s+-\s+INTERNAL\s+USE\s+ONLY)(\D|$)"
 
Isn't the problem here?
RESTRICTED [!]-[/!] INTERNAL USE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the feedback everyone. I've been slowly learning over the past couple years, and I figured out that whenever I'm racking my brain looking for a solution to something like this... it's generally a small coding error I'm overlooking... In this case, a single dash! I appreciate each of you taking the time to review. ::)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top