正则表达式适用于 Linux 但不适用于 Solaris

Regular expression works on Linux but not on Solaris

我编写了一个 C++ 程序来解析日志文件,这些日志文件写入速度太快以至于任何人都无法阅读。 该程序应该找到包含 'WARN' 之类的单词的每一行,但不包含 'WARNA' 之类的单词。 正如我所说,它在 Linux 上运行良好,但在 Solaris 上却不行。 我使用 regcomp()REG_EXTENDED 标志。

regcomp() 不会引发错误并且 regexec returns 1 (REG_NOMATCH).

我使用 regexec()regcomp()

我有一个非常长的正则表达式,它在 Linux

中运行良好
.*([^A-Za-z1-9]|\s)(error|ERROR|Error|fatal|FATAL|Fatal|excep|EXCEP|Excep|warn|WARN|Warn|problem|PROBLEM|Problem|fail|FAIL|Fail|fault|Fault|FAULT|cannot|Cannot|CanNot|CANNOT|cannot|Cannot|CANNOT|cant|can't|Cant|Can't|unable|Unable|UNABLE|mandatory|Mandatory|MANDATORY|mustnot|Mustnot|MustNot|MUSTNOT|couldnot|Couldnot|CouldNot|COULDNOT|didnot|Didnot|DidNot|DIDNOT|violat|Violat|VIOLAT|damage|Damage|DAMAGE|missing|Missing|notfinish|mandatory|Mandatory|MANDATORY|broken|Broken|BROKEN)([^a-zA-Z1-9]).*

我自己解决了这个问题。 问题是 linux 不需要正则表达式字符串开头的 ^ 或字符串末尾的 $ 。 不过对于solaris的功能来说好像是必须的