# Split Expression

**URL:** <https://forum.inductiveautomation.com/t/split-expression/102020>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 7, 2025, 12:29am UTC](https://forum.inductiveautomation.com/t/split-expression/102020 "2025-02-07T00:29:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yousef\_Ali](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@Yousef\_Ali](https://forum.inductiveautomation.com/u/Yousef_Ali)\
**Post date:** [February 7, 2025, 12:29am UTC](https://forum.inductiveautomation.com/t/split-expression/102020/1 "2025-02-07T00:29:03Z")

</div>

I have expression Tag ,value type `String`` A/B/C/D/N/M` I would like to use direct expression to return the string always the last two parts after` /` means, result for above example `A/B/C/D`  
other example  
`A/B/C/D/E/F/G` return should be `A/B/C/D/E`

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 7, 2025, 1:35am UTC](https://forum.inductiveautomation.com/t/split-expression/102020/2 "2025-02-07T01:35:42Z")

</div>

With my Integration Toolkit module:

```python
transform(
	split({[.]SourceStringTag}, '/'), // delivers a dataset, one part per row
	groupConcat( // Assembles from rows like python .join()
		where(
			value(), // The split result
			idx() < len(value()) - 2 // True for all but the last two rows
		),
		0, // Pick from column zero (the only one)
		'/' // Rejoin with the same character
	)
)

```

Something with a script if you don't have my toolkit.

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [February 7, 2025, 4:09am UTC](https://forum.inductiveautomation.com/t/split-expression/102020/3 "2025-02-07T04:09:39Z")

</div>

Below example is based on an expression tag in the same folder as a memory tag (`FullTag`) with a value of the full string.

To return **everything before last "/"** :  
`left({[.]FullTag}, lastIndexOf({[.]FullTag}, "/"))`

So, to return **everything before second-to-last "/"** :

```python
left({[.]FullTag}, lastIndexOf(
	left({[.]FullTag}, lastIndexOf({[.]FullTag}, "/"))
	, "/"))

```

🤢
