PCRE to POSIX assistance

牧云@^-^@ 提交于 2019-12-02 05:06:17

问题


I need to extract the profile for these syslog entries.

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()

The following regex works for PCRE but I can't seem to convert it over to POSIX.

(?m)profile=(\S+)

I've tried

[^=]*$

and

.*profile=(.*)

but can't get either to stop at just product_api


回答1:


POSIX ERE does not support inline regex modifiers, and shorthand character classes are not always supported. Note that even in your (?m)profile=(\S+) PCRE regex, the (?m) MULTILINE modifier is redudant as there is no ^, nor $ to redfine the behavior of. What you may use is a POSIX character class [:space:] (matching any whitespace) inside a negated bracket expression:

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

Details:

  • profile= - a literal substring
  • ([^[:space:]]+) - Group 1: one or more characters other than those that can be matched with [:space:] POSIX character class.


来源:https://stackoverflow.com/questions/43945308/pcre-to-posix-assistance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!