# substringAfter() and substringBefore() in Jira Automation

URL: https://goingstellar.ro/reference/smart-values/substringafter-substringbefore/

These functions cut a text around a separator you name: substringBefore() and substringAfter() use the first match, the Last variants use the last match, and substringBetween() returns what sits between two markers. They are the tool for pulling an id or a keyword out of a pasted title.

## Syntax

```
{{issue.summary.substringAfter("W")}}
{{issue.summary.substringBefore("W")}}
{{issue.summary.substringAfterLast("o")}}
{{issue.summary.substringBeforeLast("o")}}
{{issue.summary.substringBetween("e","d")}}
```

## Arguments

- `separator` (required: yes): The text to look for; the separator itself is not part of the result
- `open, close` (required: yes): For substringBetween(): the two markers around the part you want

## Works on

- Fields: text smart values
- Returns: text, empty when the separator is not found (except substringBefore, see pitfalls)

## Examples

```
{{issue.key.substringAfter("-")}}
```

Get the number part of an issue key. For the key WEB-44 the result is 44.

Result:

```
44
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.description.substringBefore(".")}}
```

Use the first sentence of a description as a headline.

Result:

```
Checkout page redesign
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.description.substringAfter(". ")}}
```

Keep everything after the first sentence, for a comment that quotes the details.

Result:

```
Customer reported the total is wrong.
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.description.substringBetween("the "," is")}}
```

Pull out the word between two markers. The result is the value the customer says is wrong.

Result:

```
total
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.summary.substringAfterLast(" ")}}
```

Take the last word of a title with the Last variant.

Result:

```
World!
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.key.substringAfter("-").leftPad(5, "0")}}
```

Chain: cut the number from the key and pad it to a fixed width for a reference code.

Result:

```
00043
```

Run on Jira Cloud on 29 Nov 2026.

## Where the documentation differs

- `{{issue.summary.substringBefore("W")}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `Hello`, the actual result is `Hello `.

## Pitfalls

- The documentation shows `substringBefore("W")` returning Hello. The result is Hello followed by a space, because the separator is W and the space before it stays in the text. Add trim() when you compare the result (checked on Jira Cloud, November 2026).
- When the separator is missing, substringAfter() returns an empty text but `substringBefore()` returns the whole text unchanged. Test with isEmpty() or compare the lengths before relying on it.
- substringBetween() with a single marker, or with markers that do not appear, returns an empty text rather than an error.

## Related

- [substring()](https://goingstellar.ro/reference/smart-values/substring/)
- [left() and right()](https://goingstellar.ro/reference/smart-values/left-right/)
- [indexOf() and lastIndexOf()](https://goingstellar.ro/reference/smart-values/indexof/)
- [split()](https://goingstellar.ro/reference/smart-values/split/)
- [trim()](https://goingstellar.ro/reference/smart-values/trim/)
- [isEmpty() and isNotEmpty()](https://goingstellar.ro/reference/smart-values/isempty-isnotempty/)

## Sources

- [Jira smart values: text fields (Atlassian Support)](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/)

