Prototype: escape(text)

Return type: string

Description: Escape regular expression characters in text.

This function is useful for making inputs readable when a regular expression is required, but the literal string contains special characters. The function simply 'escapes' all the regular expression characters, so that you do not have to.


  • text : IP address or string to escape, in the range .*


    bundle server control
      allowconnects => { "127\.0\.0\.1", escape("") };

In this example, the string "" is "escaped" to be equivalent to "192\.168\.2\.1", because without the backslashes, the regular expression "" will also match the IP ranges "192.168.201", "192.168.231", etc (since the dot character means "match any character" when used in a regular expression).


History: This function was introduced in CFEngine version 3.0.4 (2010)