Search code examples
javascriptnode.jsregexfluentd

pipe as delimiter in regular expression


2020-09-16 04:47:49 | info | PHP | BACKEND | 01ARZ3NDEKTSV4RRFFQ69G5FAV | Login not successfully. Please try again

Above is my sample logging format which will be sent to fluentd, and I did regular expression as follow:

<parse>
  time_format %Y-%m-%d %H:%M:%S
  expression /^(?<timestamp>(.*?\|))(?<level>(.*?\|))(?<language>(.*?\|))(?<service>(.*?\|))(?<uuid>(.*?\|))(?<message>.*)/
  @type regexp
</parse>

Problem is when I render that one, pipe | is included in string. Please let me know how to ignore or skip | there? Thanks.


Solution

  • Just move the | outside of your group: ^(?<timestamp>(.*?))\|(?<level>(.*?))\|(?<language>(.*?))\|(?<service>(.*?))\|(?<uuid>(.*?))\|(?<message>.*)

    See: https://regex101.com/r/8rFRPa/2