---
schema_version: "1"
id: fc64ea09aaddd92cf8e8a9b45415395c5b289ae9da15256f5f4adc429837b229
title: substringBeforeLast
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-strings-functions-substringbeforelast.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-strings-functions-substringbeforelast
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 1f81eee310493f8d21533d0c5e5532b44de084a1d969dac223c1687a0ef67fa5
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# substringBeforeLast

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## substringBeforeLast(text: String, separator: String): String

Gets the substring before the last occurrence of a separator. The separator is not returned.

_Introduced in DataWeave version 2.2.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>The input string.</p></td></tr><tr><td><p><code>separator</code></p></td><td><p>String to search for.</p></td></tr></tbody></table>

### Example

This example shows how `substringBeforeLast` behaves with different inputs and sizes.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
  "a": substringBeforeLast(null, "'"),
  "b": substringBeforeLast("", "-"),
  "c": substringBeforeLast("abc", "b"),
  "d": substringBeforeLast("abcba", "b"),
  "e": substringBeforeLast("abc", "d"),
  "f": substringBeforeLast("abc", "")
}
```

#### Output

```JSON
{
  "a": null,
  "b": "",
  "c": "a",
  "d": "abc",
  "e": "",
  "f": "ab"
}
```

## substringBeforeLast(text: Null, separator: String): Null

Helper function that enables `substringBeforeLast` to work with a `null` value.

_Introduced in DataWeave version 2.2.0._
