in reply to can't find mistake. using sort and slice in regex

You're not saying how it doesn't work. Wrong result? Can you please show where it is getting wrong, then?

One thing I might try to change in your code is to replace your sort line with this:

s/(\d+)(?= (\d+))/ $1 > $2 ? $1 : $2/eg;
as using sort just for retrieving the largest of two variables seems a bit of an overkill. I think that the intent gets clearer. But this will probably produce the same result. So we are back to my first question: where is it wrong?

Update: I had not seen that the line I suggested just above was in your commented out code lines. I tried the code as you have it and also with the code line suggested just above, they seem to produce the same output.

Je suis Charlie.