SOLVED
Home

Transport rule for message encryption with regex

Highlighted
Stephen Bell
Contributor

Transport rule for message encryption with regex

Hello all, 

 

I am looking to setup a transport rule in the GUI for message encryption.  I have already tested that encryption is configured correctly as I have a rule that I was playing with which says if the word "encrypt" is in the subject, encrypt the message.

 

Now I am looking to get a little more specific - I would like the rule to match the subject on a regex looking for [encrypt] - in a case INSENSITIVE way (so [Encrypt] or [eNCryPt] would encrypt the message.

 

I have a regex that seems to validate:

/\[encrypt\]/gi - but when I add this to the rule - it does not seem to encrypt the message.  I am nowhere near a regex expert (though I hear they do exist).  So I am reaching out to those with more experience in this area.

 

Thank you

steve

1 Reply
Solution

Re: Transport rule for message encryption with regex

I am by no means a regex expert, but a quick google and a bit of trial and error suggests the following may work:

 

(?:^|\W|\w)\[encrypt\](?:$|\W|\w)

 

Test in PowerShell:

$regex = "(?:^|\W|\w)\[encrypt\](?:$|\W|\w)"

"### Should be true ###"
"[encrypt]" -match $regex
"[ENCRYPT]" -match $regex
"[Encrypt]" -match $regex
"[encrypt] test" -match $regex
"test [encrypt]" -match $regex
"test[encrypt]" -match $regex
"[encrypt]test" -match $regex
"### Should be false ###"
"[encr1ypt]" -match $regex
"do not encrypt" -match $regex

Which returns

### Should be true ###
True
True
True
True
True
True
True
### Should be false ###
False
False