# Remove starting and ending forward slash

**URL:** <https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659>\
**Category:** Logstash\
**Created:** [August 1, 2018, 11:56pm UTC](https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659 "2018-08-01T23:56:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishek007](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@abhishek007](https://discuss.elastic.co/u/abhishek007)\
**Post date:** [August 1, 2018, 11:56pm UTC](https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659/1 "2018-08-01T23:56:39Z")

</div>

Hi,  
I have to get rid of the starting forward slash in a field value.  
Field value is "/abc/par/xyz/"  
I want this ti be muted as abc\_par\_xyz  
I can replace '/' with '\_' using gsub, but it gives me "_abc\_par\_xyz_"  
How can I get rid of first and last '/'

Br,  
AB

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 2, 2018, 1:09am UTC](https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659/2 "2018-08-02T01:09:41Z")

</div>

Did you read what you posted? Your post says you want abc\_par\_xyz, but you get abc\_par\_xyz, which is the same thing. So it is unclear what you want. Perhaps you want to anchor you regexps in gsub?

```
mutate { gsub => ["message", "^/", "", "message", "/$", "", "message", "/", "_"] }
```

---

<div class="post-metadata">

**Author:** ![abhishek007](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@abhishek007](https://discuss.elastic.co/u/abhishek007)\
**Post date:** [August 2, 2018, 1:48am UTC](https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659/3 "2018-08-02T01:48:41Z")

</div>

Hi,  
I don't know why prefix underscore not appearing in my post. When I edit, it shows, but when I save, it's not showing. However it gives me string whcih starts with underscore and ends with underscore, Which I don't want.  
I want to get rid of starting and ending underscore character.

I hope you understand my problem.

---

<div class="post-metadata">

**Author:** ![abhishek007](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@abhishek007](https://discuss.elastic.co/u/abhishek007)\
**Post date:** [August 2, 2018, 2:34am UTC](https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659/4 "2018-08-02T02:34:28Z")

</div>

Thanks a lot.  
It worked.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 30, 2018, 2:34am UTC](https://discuss.elastic.co/t/remove-starting-and-ending-forward-slash/142659/5 "2018-08-30T02:34:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
