PCRE 提供 POSIX 援助

PCRE to POSIX assistance

我需要提取这些系统日志条目的配置文件。

May 11 09:35:59 server-0548 ea_appserver: env=ACPT profile=product_api java[31185]: 2017-05-11 09:35:59,210 server-0548 org.hibernate.internal.SessionFactoryImpl ServerService Thread Pool -- 51 HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()

以下正则表达式适用于 PCRE,但我似乎无法将其转换为 POSIX。

(?m)profile=(\S+)

我试过了

[^=]*$

.*profile=(.*)

但都不能停在 product_api

POSIX ERE 不支持内联正则表达式修饰符,并且 shorthand 字符 classes 并不总是受支持。请注意,即使在您的 (?m)profile=(\S+) PCRE 正则表达式中,(?m) MULTILINE 修饰符也是 redudant,因为没有 ^,也没有 $重新定义的行为。您可以使用的是 POSIX 字符 class [:space:] (匹配任何空格)在否定括号表达式中:

profile=([^[:space:]]+)

详情:

  • profile= - 文字子串
  • ([^[:space:]]+) - 第 1 组:除 [:space:] POSIX 字符 class.
  • 之外的一个或多个字符