---
updatedAt: 2026-10-29T21:17:18.000Z
agentTools:
  projectIndex: https://docs.sublime.security/llms.txt
---

# Strings functions

Functions in the `strings` module

<a id="concat"></a>

# `strings.concat`

`strings.concat(sub: string, ...) -> string`

`concat` combines multiple strings together in order. This could be used later by other string comparisons or list lookups.

### Examples

```javascript MQL
strings.concat("no-reply", "@sublimesecurity.com") -> "no-reply@sublimesecurity.com"
strings.concat(null, "@sublimesecurity.com") -> null
strings.concat(sender.email.local_part, "@different-domain.com") -> "sender_local@different-domain.com"

// Escaped email in a URL (@ escapes to %40)
strings.concat(sender.email.local_part, "%40", sender.email.domain.domain)
```

<a id="contains--icontains"></a>

# `strings.contains` / `strings.icontains`

`strings.contains(source: string, substring: string, ...) -> bool`<br />`strings.icontains(source: string, substring: string, ...) -> bool`

`contains` is used to check if one source string contains any of the specified substrings. `contains` performs a case-sensitive substring search, but `icontains` is case-insensitive. These strings can be literal strings, fields, or values from functions.

If the source string is `null`, or all of the specified substrings are `null`, then `contains` and `icontains` will return null.

### Examples

```javascript MQL
strings.contains("no-reply@sublimesecurity.com", "@sublimesecurity.com") -> true
strings.contains("no-reply@sublimesecurity.com", "support", "@sublime") -> true
strings.contains("no-reply@sublimesecurity.com", "@SuBLiMe", "NO-REPLY") -> false
strings.icontains("no-reply@sublimesecurity.com", "@SuBLiMe") -> true
strings.icontains("no-reply@sublimesecurity.com", null) -> null
```

<a id="count--icount"></a>

# `strings.count` / `strings.icount`

`strings.count(source: string, substring: string) -> integer`<br />`strings.icount(source: string, substring: string) -> integer`

`count` is used to count the number of occurrences of a substring within another string. `count` only counts `case-sensitive` occurrences but `icount` counts all case-insensitive occurrences. These strings can be literal strings, fields, or values from functions.

If either string is `null`, then `count` and `icount` will return null.

### Examples

```javascript MQL
strings.count("An example string to search", " ") -> 4
strings.count("Banana nana nana", "na") -> 6
strings.icount("BaNaNa NaNa NaNa", "NA") -> 6
```

<a id="decode_base64"></a>

# `strings.decode_base64`

The `strings.decode_base64` function decodes base64-encoded strings. This is particularly useful for detecting phishing attacks where threat actors encode sensitive information like recipient email addresses within URLs or QR codes.

```javascript MQL

strings.decode_base64(
    text: string,
    encodings=["ascii", "utf8", "utf16"],
    ignore_padding=false,
    format="standard"
) -> string
```

* `text` (required): The base64-encoded string to decode
* `encodings` (optional): Array of string encodings to attempt when decoding base64 content
  * Supported values: `"ascii"`, `"utf8"`, `"latin1"`, `"windows1252"`, `"utf16"`, `"utf16-be"`, `"utf16-le"`
  * Default: `["ascii", "utf8", "utf16"]`
* `ignore_padding` (optional): Boolean flag to control base64 padding handling
  * Default: false
  * When true: Attempts to decode even with missing padding
  * When false: Strictly enforces proper base64 padding
* `format` (optional): Base64 alphabet to decode with
  * Supported values: `"standard"`, `"url"`
  * Default: `"standard"`

Returns a string if the input text successfully decodes. If not, it returns `null`.

<a id="decode_hex"></a>

# `strings.decode_hex`

The `strings.decode_hex` function decodes a hex-encoded string. It returns `null` if the input is not valid hex or cannot be decoded with the specified encoding.

```javascript MQL
strings.decode_hex(text: string, encodings=["ascii"]) -> string
```

* `text` (required): The hex-encoded string to decode
* `encodings` (optional): Array of string encodings to attempt. Supported values are `"ascii"`, `"utf8"`, `"latin1"`, `"windows1252"`, `"utf16"`, `"utf16-be"`, and `"utf16-le"`. The default is `["ascii"]`.

### Examples

```javascript MQL
strings.decode_hex("48656c6c6f") -> "Hello"
strings.decode_hex("e4b896e7958c", encodings=["utf8"]) -> "世界"
```

<a id="ends_with--iends_with"></a>

# `strings.ends_with` / `strings.iends_with`

`strings.ends_with(source: string, suffix: string, ...) -> bool`<br />`strings.iends_with(source: string, suffix: string, ...) -> bool`

`ends_with` is used to check if one source string has any of the specified suffixes. `ends_with` performs a case-sensitive suffix check, but `iends_with` is case-insensitive. These strings can be literal strings, fields, or values from functions.

If the source string is `null`, or all of the suffix strings are `null`, then `ends_with` and `iends_with` will return null.

### Examples

```javascript MQL
strings.ends_with("no-reply@sublimesecurity.com", "@sublimesecurity.com") -> true
strings.ends_with("no-reply@sublimesecurity.com", "security", "@sublime") -> false
strings.ends_with("no-reply@sublimesecurity.com", "@SublimeSecurity.com") -> false
strings.iends_with("no-reply@sublimesecurity.com", "@SublimeSecurity.com", "noreply") -> true
strings.iends_with("no-reply@sublimesecurity.com", null) -> null
```

<a id="like--ilike"></a>

# `strings.like` / `strings.ilike`

`strings.like(input: string, pattern: string, ...) -> bool`<br />`strings.ilike(input: string, pattern: string, ...) -> bool`

`like` is used to match a string against a list of predefined wildcard patterns. `like` performs a case-sensitive match against the entire string, but `ilike` is case-insensitive. Use wildcard characters to represent unknown substrings:

* `*` is a placeholder for a string of any length, including empty strings
* `?` is a placeholder for a single character within the string

Remember that `like` and `ilike` are evaluated against the entire string. To look for a substring, wrap it in `*`, such as `strings.ilike(body.plain.raw, "*password*")`, or use `strings.icontains(body.plain.raw, "password")`.

If `input` is `null`, then `like` and `ilike` will always return null.

### Examples

```javascript MQL
strings.like("no-reply@sublimesecurity.com", "*@sublimesecurity.com") -> true

// use ilike for case-insensitive matches
strings.like("no-reply@SublimeSecurity.com", "*@sublimesecurity.com") -> false
strings.ilike("no-reply@SublimeSecurity.com", "*@sublimesecurity.com") -> true

// if multiple wildcard patterns are specified, only one needs to match
strings.like("no-reply@sublimesecurity.com", "*@*.org", "*@*.com", "*@*.gov") -> true

// use ? to match exactly 1 unknown character
strings.like("no-reply@sublimesecurity.com", "no-?????@sublimesecurity.com") -> true
strings.like("no-reply@sublimesecurity.com", "no-?@sublimesecurity.com") -> false
```

<a id="levenshtein--ilevenshtein"></a>

# `strings.levenshtein` / `strings.ilevenshtein`

`strings.levenshtein(a: string, b: string) -> integer`<br />`strings.ilevenshtein(a: string, b: string) -> integer`

`levenshtein` is used to calculate the [Levenshtein edit distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings. The returned value is equal to the minimum number of character operations (deletion, insertion, substitution) required to transform one string into the other. `levenshtein` finds the case-sensitive distance between the two strings, but `ilevenshtein` is case-insensitive.

```javascript MQL
strings.levenshtein('Bat', 'bot') -> 2
strings.ilevenshtein('Bat', 'bot') -> 1
```

<a id="parse_domain"></a>

# `strings.parse_domain`

`strings.parse_domain(text: string) -> Domain`

`strings.parse_domain` is used to parse a string into an MDM Domain object, like the one at `sender.email.domain.root_domain`.

* `text` (required): The input text of the domain

If a domain cannot be parsed, the resulting object will be `null`.

```javascript MQL
strings.parse_domain("www.sublimesecurity.com")
```
```json Result
{
  "domain": "www.sublimesecurity.com",
  "root_domain": "sublimesecurity.com",
  "sld": "sublimesecurity",
  "subdomain": "www",
  "tld": "com",
  "valid": true
}
```

<a id="parse_email"></a>

# `strings.parse_email`

`strings.parse_email(text: string) -> EmailAddress`

`strings.parse_email` is used to parse a string into an MDM EmailAddress object, like the one at `sender.email`.

* `text` (required): The input text of the email address.

If an email address cannot be parsed, the resulting object will be `null`.

```javascript MQL
strings.parse_email("foo@sublimesecurity.com")
```
```json Result
{
  "email": "foo@sublimesecurity.com",
  "local_part": "foo",
  "domain": {
    "domain": "sublimesecurity.com",
    "root_domain": "sublimesecurity.com",
    "sld": "sublimesecurity",
    "tld": "com",
    "valid": true
  }
}
```

<a id="parse_html"></a>

# `strings.parse_html`

`strings.parse_html(input: string) -> HTML`

`strings.parse_html` is used to parse arbitrary strings as HTML and return the full raw along with display\_text and inner\_text. This is useful when the HTML you want to parse isn't a file or attachment (for example, a body fragment, a snippet extracted from another field via regex.extract, decoded base64 content, or text returned by another enrichment).

```javascript MQL
strings.parse_html("<p>Sublime Security</p>")
```
```json Result
{
  "raw": "<p>Sublime Security</p>",
  "inner_text": "Sublime Security",
  "display_text": "Sublime Security"
}

```

<a id="parse_json"></a>

# `strings.parse_json`

`strings.parse_json(j: string) -> object`

`strings.parse_json` is used to parse a raw JSON string into an MQL JSON object.

If the JSON cannot be parsed, the resulting object will be `null`.

You can traverse the resulting JSON object using the syntax as described on the [composite type syntax page](https://docs.sublime.security/docs/composite-type-syntax#json-type)

<a id="parse_time"></a>

# `strings.parse_time`

`strings.parse_time(source: string) -> timestamp`

Parses a date and time string into a timestamp for [comparisons and arithmetic](https://docs.sublime.security/docs/syntax#timestamp-and-duration-arithmetic). It accepts one string argument and uses the following formats automatically:

| Format                                                | Example                                                       |
| :---------------------------------------------------- | :------------------------------------------------------------ |
| RFC 3339, including fractional seconds                | `2026-10-02T14:03:04Z`, `2026-10-02T14:03:04.123456789+02:30` |
| ISO 8601 date and time with an offset without a colon | `2026-10-02T14:03:04-0700`                                    |
| RFC 1123 with a numeric offset                        | `Fri, 02 Oct 2026 14:03:04 +0000`                             |
| RFC 822 with a numeric offset                         | `02 Oct 26 14:03 +0000`                                       |
| ANSI C date and time                                  | `Fri Oct  2 14:03:04 2026`                                    |
| Date and time separated by a space                    | `2026-10-02 14:03:04`                                         |

When the string includes a time zone, use `Z` or a numeric offset such as `-07:00`. If it has no time zone, the function interprets it as UTC.

Returns `null` for a `null` input, an empty string, an invalid date, or an unsupported format.

### Examples

```javascript MQL
strings.parse_time('2026-10-02 14:03:04') == strings.parse_time('2026-10-02T14:03:04Z') -> true
headers.date >= strings.parse_time('2026-10-02T00:00:00Z')
strings.parse_time('2026-10-02') -> null
strings.parse_time('not a date') -> null
strings.parse_time(null) -> null
```

<a id="parse_url"></a>

# `strings.parse_url`

`strings.parse_url(text: string, strict=true) -> URL`

`strings.parse_url` parses a string into an MDM URL object, such as the one at `body.links[].href_url`.

* `text` (required): The input text of a URL.
* `strict` (optional): If true, the URL must have an explicit scheme, such as `https://`. To parse a URL without a scheme, manually set `strict = false`

```javascript MQL
strings.parse_url("https://www.sublimesecurity.com")
```
```json Result
{
  "url": "https://www.sublimesecurity.com",
  "domain": {
    "domain": "www.sublimesecurity.com",
    "root_domain": "sublimesecurity.com",
    "sld": "sublimesecurity",
    "subdomain": "www",
    "tld": "com",
    "valid": true
  },
  "scheme": "https"
}
```

```javascript MQL
strings.parse_url("www.sublimesecurity.com", strict=false)
```
```json Result
{
  "url": "https://www.sublimesecurity.com",
  "domain": {
    "domain": "www.sublimesecurity.com",
    "root_domain": "sublimesecurity.com",
    "sld": "sublimesecurity",
    "subdomain": "www",
    "tld": "com",
    "valid": true
  },
  "scheme": "https"
}
```

<a id="scan_base64"></a>

# `strings.scan_base64`

The `strings.scan_base64` function identifies base64 encoded strings within text content and decodes them into readable strings. This is particularly useful for detecting phishing attacks where threat actors encode sensitive information like recipient email addresses within URLs or QR codes.

#### Key Use Cases

* Detecting recipient information encoded in phishing URLs
* Identifying encoded domains or usernames in message content
* Analyzing HTML attachments for encoded data

### Technical Specification

#### Syntax

```javascript MQL

strings.scan_base64(
    text: string,
    encodings=["ascii", "utf8", "utf16"],
    ignore_padding=false,
    multiline=true,
    format="standard"
) -> []string
```

#### Parameters

* `text` (required): The input text to scan for base64 encoded content
* `encodings` (optional): Array of string encodings to attempt when decoding base64 content
  * Supported values: `"ascii"`, `"utf8"`, `"latin1"`, `"windows1252"`, `"utf16"`, `"utf16-be"`, `"utf16-le"`
  * Default: `["ascii", "utf8", "utf16"]`
* `ignore_padding` (optional): Boolean flag to control base64 padding handling
  * Default: false
  * When true: Attempts to decode even with missing padding
  * When false: Strictly enforces proper base64 padding
* `multiline` (optional): Whether to join base64 content split across multiple lines
  * Default: true
* `format` (optional): Base64 alphabet to decode with
  * Supported values: `"standard"`, `"url"`
  * Default: `"standard"`

#### Return Value

Returns an array of successfully decoded strings that were found in the input text. If no base64 string is found, it returns an empty array of strings.

<a id="scan_hex"></a>

# `strings.scan_hex`

The `strings.scan_hex` function finds hex-encoded strings in text and returns their decoded values. It skips values that cannot be decoded with the specified encoding.

```javascript MQL
strings.scan_hex(text: string, encodings=["ascii"]) -> []string
```

* `text` (required): The text to scan for hex-encoded strings
* `encodings` (optional): Array of string encodings to attempt. Supported values are `"ascii"`, `"utf8"`, `"latin1"`, `"windows1252"`, `"utf16"`, `"utf16-be"`, and `"utf16-le"`. The default is `["ascii"]`.

Returns an empty array if no decodable hex string is found.

### Examples

```javascript MQL
strings.scan_hex("https://example.com/726f7373407375626c696d652e7365637572697479") -> ["ross@sublime.security"]
strings.scan_hex("e4b896e7958c", encodings=["utf8"]) -> ["世界"]
```

<a id="starts_with--istarts_with"></a>

# `strings.starts_with` / `strings.istarts_with`

`strings.starts_with(source: string, prefix: string, ...) -> bool`<br />`strings.istarts_with(source: string, prefix: string, ...) -> bool`

`starts_with` is used to check if one source string starts with any of the specified prefixes. `istarts_with` performs the same operation but is case-insensitive. The prefixes can be literal strings, fields, or values from functions.

If the source string is `null`, or all of the prefix strings are `null`, then `starts_with` and `istarts_with` will return `null`.

### Examples

```javascript MQL
strings.starts_with("no-reply@sublimesecurity.com", "no-reply") -> true
strings.starts_with("no-reply@sublimesecurity.com", "@sublime", "reply") -> false
strings.starts_with("no-reply@sublimesecurity.com", "No-Reply") -> false
strings.istarts_with("no-reply@sublimesecurity.com", "No-Reply", "sublime") -> true
strings.istarts_with("no-reply@sublimesecurity.com", null) -> null
```