1

I have following texts:

elasticsearch_sync_queue_lowerlevelgiberish_ManualAllocationPolicy:pending
elasticsearch_sync_queue_SynchronizationProcessor:processing

I'd like to extract text and value like:

text=ManualAllocationPolicy 
value=elasticsearch_sync_queue_lowerlevelgiberish_ManualAllocationPolicy
text=SynchronizationProcessor
value=elasticsearch_sync_queue_SynchronizationProcessor

I've used this expression but I'm not able to remove the text :*.

^(?=.*?(?<text>[A-Z][^:]*))(?<value>[^:]+)

https://regex101.com/r/lGhrPu/1

EDIT: This is being used in a Grafana variable, so the result of query might be little bit different.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
bilak
  • 4,526
  • 3
  • 35
  • 75
  • Maybe I did not understand correctly but I think you just need to change the Regex101 "function" to **List** (print using vars) instead of **Substitution** (replace in original string). – AymDev Apr 28 '23 at 09:37
  • 1
    Maybe `^(?[^:\n]*?_(?[^:_]+)):`? See https://regex101.com/r/lGhrPu/2 – Wiktor Stribiżew Apr 28 '23 at 09:44
  • @AymDev no no I don't need list. If you look into substitution it still produces `:processing` at the end. I'm using this in grafana and it doesn't produce the output with given expression. So something is probably wrong even there. – bilak Apr 28 '23 at 09:46

2 Answers2

2

Your capturing groups are working fine. You should either be using the List function on Regex101, or complete the expression to include the missing parts by adding :.*$ at the end:

^(?=.*?(?<text>[A-Z][^:]*))(?<value>[^:]+):.*$

Substitution is used to replace in a string, leaving the unmatching part in the output.

AymDev
  • 6,626
  • 4
  • 29
  • 52
0

You could try this one (?<value>.*_(?<text>[^:_]*)):

https://regex101.com/r/JpCAva/1

The idea is to utilize the last _ separator by specifying it between the groups (or in this case inside the value group)

Nikita Chayka
  • 2,057
  • 8
  • 16