Telegraf Regex 表达式获取最后一个字符串

Telegraf Regex expression to fetch last string

根据我的要求,我想获取字符串中的最后几个字符。 例如我的字符串是“hello/how/are/you”,这里我只想要“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 = "[=10=]"
    result_key = "resource_type"

但我没有得到预期的输出,即“are/you”。谁能帮我解释一下这个表达式?

我不懂那种语言 但是对于正则表达式

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

使用

.*(are.*)

在您的代码段中:

[[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 = ""
    result_key = "resource_type"

regex proof

解释

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  (                        group and capture to :
--------------------------------------------------------------------------------
    are                      'are'
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )                        end of