singe batteur singe batteur - 4 months ago 13
YAML Question

how to invert keys and values in a YAML file (key : value)

I have a big

.yml
translation file, in which I would like to invert the keys and the values.

what I have :

some english sentence : une phrase en francais
another one : une autre


what I would like to get :

une phrase en francais : some english sentence
une autre : another one


I'm sure there might be a bunch of easy regex to do so, but I could not figure out how to do this ...

I dont search a script, just a regex

Answer

The regex:

(.*)\s+:\s+(.*)

The substitution:

$2 : $1

Demo: https://regex101.com/r/lU6eM4/2