Forum Discussion

Stephen Bell's avatar
Stephen Bell
Iron Contributor
Oct 06, 2016

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...
  • Chris Brown's avatar
    Oct 06, 2016

    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

Resources