# Ruby + replace from array lines

**URL:** <https://discuss.elastic.co/t/ruby-replace-from-array-lines/246647>\
**Category:** Logstash\
**Created:** [August 27, 2020, 2:53pm UTC](https://discuss.elastic.co/t/ruby-replace-from-array-lines/246647 "2020-08-27T14:53:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thaideval](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@thaideval](https://discuss.elastic.co/u/thaideval)\
**Post date:** [August 27, 2020, 2:53pm UTC](https://discuss.elastic.co/t/ruby-replace-from-array-lines/246647/1 "2020-08-27T14:53:00Z")

</div>

Hello there.  
First of all i am not even sure if its possible, but figured - should still ask.  
so.. i have two fields.

1. String with text:  
{field1} = "Some text from blah X.KEY1 Some more text X.KEY2 and text here... "
2. Array with translation  
"Regions" =\> [  
[0] "KEY1-good",  
[1] "KEY2-good"  
],  
I want to translate KEY1 in field1 into KEY1-good and KEY2 into KEY2-good.

The trick is - i do not know how many "keys" can be in the {field1}. Plus they can be almost the same so translate filter wont work.  
But position in {Regions} always right. so %{[Regions][0]} is KEY1 in %{field1} and so on...  
I though i should use ruby, but cant figure out how? should it be .map or gsub? and how can i corelate position in %{Region} and position in ruby scan?

---

<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:** [September 24, 2020, 2:53pm UTC](https://discuss.elastic.co/t/ruby-replace-from-array-lines/246647/2 "2020-09-24T14:53:02Z")

</div>

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