Search code examples
regextelegraftelegraf-plugins

Telegraf Regex expression to fetch last string


As per my requirement I want to fetch last few characters in a string. For example my string is "hello/how/are/you", here I want only "are/you".

[[processors.regex]]
  order = 1305
  namepass = ["*_promitor_test"]
  # Tag and field conversions defined in a separate sub-tables
  [[processors.regex.tags]]
    ## Tag to change
    key = "resource"
    ## Regular expression to match on a tag value
    pattern = "^(.*)$/are.*"
    ## Matches of the pattern will be replaced with this string.
    replacement = "${0}"
    result_key = "resource_type"

But I am not getting expected output i.e. "are/you". Can anybody please help me with this expression?


Solution

  • I don't know that language but for the regex

       #edited the regex
       pattern = "^(.*)(are.*)$"
       #group number starts from 1 not 0 
       replacement = "${2}"