PCRE 到 POSIX 的帮助 [英] PCRE to POSIX assistance
问题描述
我需要提取这些系统日志条目的配置文件.
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线程池 -- 51 HHH000008:JTASessionContext 与 JDBCTransactionFactory 一起使用;使用 getCurrentSession() 自动刷新将无法正常运行
以下正则表达式适用于 PCRE,但我似乎无法将其转换为 POSIX.
The following regex works for PCRE but I can't seem to convert it over to POSIX.
(?m)profile=(\S+)
我试过了
[^=]*$
和
.*profile=(.*)
但不能只停留在 product_api
推荐答案
POSIX ERE 不支持内联正则表达式修饰符,并且并不总是支持速记字符类.请注意,即使在您的 (?m)profile=(\S+)
PCRE 正则表达式中,(?m)
MULTILINE 修饰符也是 冗余,因为那里不是 ^
,也不是 $
来重新定义行为.您可能使用的是否定括号表达式内的 POSIX 字符类 [:space:]
(匹配任何空格):
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:]]+)
详情:
profile=
- 文字子串([^[:space:]]+)
- 第 1 组:除了可以与[:space:]
POSIX 匹配的字符之外的一个或多个字符字符类.
profile=
- a literal substring([^[:space:]]+)
- Group 1: one or more characters other than those that can be matched with[:space:]
POSIX character class.
这篇关于PCRE 到 POSIX 的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!