# Escaping a forward slash / in a regex match

**URL:** <https://discuss.elastic.co/t/escaping-a-forward-slash-in-a-regex-match/320828>\
**Category:** Elasticsearch\
**Tags:** painless, ingest-pipeline\
**Created:** [December 8, 2022, 8:05pm UTC](https://discuss.elastic.co/t/escaping-a-forward-slash-in-a-regex-match/320828 "2022-12-08T20:05:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gentle\_ghost](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gentle\_ghost](https://discuss.elastic.co/u/gentle_ghost)\
**Post date:** [December 8, 2022, 8:05pm UTC](https://discuss.elastic.co/t/escaping-a-forward-slash-in-a-regex-match/320828/1 "2022-12-08T20:05:41Z")

</div>

Hello,

This should be rather simple but I'm definitely overthinking this. I've tried escaping a forward slash in a regex match for a painless script in an ingest pipeline and it fails every combination I try. I have the following ingest pipeline script. Original without any attempts at escapes:

```auto
 if (ctx.position ==~ /.*yiut/houst.*/) {
    ctx.location = "Yiut - Houston";
  } else {
  if (ctx.position ==~ /.*yiut/atl.*/) {
    ctx.location = "Yiut - Atlanta";
  else {
    ctx.location = "Unknown Location";
  }

```

How would I properly escape the forward slash in this regex match? Its getting a little frustrating painless can be anything but.

Thanks

---

<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:** [January 5, 2023, 8:05pm UTC](https://discuss.elastic.co/t/escaping-a-forward-slash-in-a-regex-match/320828/2 "2023-01-05T20:05:55Z")

</div>

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