Hi, On Fri, Jun 29, Baptiste wrote: > converters are just simple C functions, (or could be Lua code as well), and > are quite trivial to write. > Instead of creating a converter that reverse the order of chars in a > string, I would rather patch current "word" converter to support negative > integers. > IE: -2 would means you extract the second word, starting at the end of the > string.
No need to patch "word" for negative indexes. The functionality is already there: commit 9631a28275b7c04f441f7d1c3706a765586844e7 Author: Marcin Deranek <marcin.dera...@booking.com> Date: Mon Apr 16 14:30:46 2018 +0200 MEDIUM: sample: Extend functionality for field/word converters Extend functionality of field/word converters, so it's possible to extract field(s)/word(s) counting from the beginning/end and/or extract multiple fields/words (including separators) eg. str(f1_f2_f3__f5),field(2,_,2) # f2_f3 str(f1_f2_f3__f5),field(2,_,0) # f2_f3__f5 str(f1_f2_f3__f5),field(-2,_,3) # f2_f3_ str(f1_f2_f3__f5),field(-3,_,0) # f1_f2_f3 str(w1_w2_w3___w4),word(3,_,2) # w3___w4 str(w1_w2_w3___w4),word(2,_,0) # w2_w3___w4 str(w1_w2_w3___w4),word(-2,_,3) # w1_w2_w3 str(w1_w2_w3___w4),word(-3,_,0) # w1_w2; -Jarno > On Mon, Jun 25, 2018 at 12:29 PM, Daniel Schneller < > daniel.schnel...@centerdevice.com> wrote: > > > Hi! > > > > Just double checking to make sure I am not simply blind: Is there a way to > > reverse a string using a sample converter? > > > > Background: I need to extract just the second level domain from the host > > header. So for sub.sample.example.com I need to fetch "example". > > > > Using the "word" converter and a "." as the separator I can get at the > > individual components, but because the number of nested subdomains varies, > > I cannot use that directly. > > > > My idea was to just reverse the full domain (removing a potential port > > number first), get word(2) and reverse again. Is that possible? Or is there > > an even better function I can use? I am thinking this must be a common use > > case, but googling "haproxy" and "reverse" will naturally turn up lots of > > results talking about "reverse proxying". > > > > If possible, I would like to avoid using maps to keep this thing as > > generic as possible. > > > > Thanks a lot! > > > > Daniel -- Jarno Huuskonen