# Split Regex "\\" doesn't work

**URL:** <https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638>\
**Category:** Ignition\
**Created:** [May 10, 2016, 5:25am UTC](https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638 "2016-05-10T05:25:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [May 10, 2016, 5:25am UTC](https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638/1 "2016-05-10T05:25:31Z")

</div>

I am trying to split out the filename from a file path.

If the file path is:

```auto
D:\General\Manuals\Omron\PLC\NJ_NX_Motion Control User Manual_W507-E1-11.pdf
```

I want to extract the filename:

```auto
NJ_NX_Motion Control User Manual_W507-E1-11.pdf
```

I thought I could use something like:

```auto
split({Root Container.FilePath}, '\')[5,0]
```

But i'm getting the error:

> [@](#):
>
> Scan Error: Unterminated string at end of line (Line 1, Char 43)

Where Char 43 is the end of the expression.

Is the "" character one of those funny characters which cannot be used directly? Do you need to use some other syntax like "\" or """"?

Thanks

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [May 10, 2016, 10:36am UTC](https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638/2 "2016-05-10T10:36:57Z")

</div>

Yes a backslash needs to be doubled.  
So just do

```auto
s = {Root Container.FilePath}
print s.rsplit("\\",1)
```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 10, 2016, 11:56am UTC](https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638/3 "2016-05-10T11:56:49Z")

</div>

If you’re just looking to extract the filename, you can use rfind() to find the rightmost occurrence. This way, you can also easily keep the path, if you so choose.

[code]fullPath = ‘D:\General\Manuals\Omron\PLC\NJ\_NX\_Motion Control User Manual\_W507-E1-11.pdf’

splitPoint = fullPath.rfind(’\’)

path = fullPath[:splitPoint+1]  
fileName = fullPath[splitPoint+1:]

print path  
print fileName [/code]  
[attachment=0]2016-05-10\_7-52-39.png[/attachment]

---

<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:** [May 10, 2016, 12:14pm UTC](https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638/4 "2016-05-10T12:14:52Z")

</div>

Not only do you have to double the backslash in a quoted string, in a regex to have it as a normal character, you have to double it again. In python, you can use the raw string syntax to avoid interpreting backslashes (the first doubling). The expression system doesn’t have that option. So, in an expression:`split({Root Container.FilePath}, '\\\\')[5,0]`

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [May 10, 2016, 8:59pm UTC](https://forum.inductiveautomation.com/t/split-regex-doesnt-work/11638/5 "2016-05-10T20:59:54Z")

</div>

Ah… the ol double down. 😛

I tried “”, “\” and “\”, but who would have thought to do “\\”!

Awesome thanks for the replies everyone.
