我正在尝试使用以下代码解析linux ps fuxa输出的输出(我从{3}开始用于测试目的,我意识到由于小数点解析失败。我的目标是找到THE_PACKAGE ):
import parsley
x = parsley.makeGrammar("""
anything_followed_by_a_space = <anything+> ws
rpm = anything_followed_by_a_space{3} <anything+>:name_of_the_rpm -> (name_of_the_rpm)
""", {})
print x("root 26250 0.0 0.0 108208 1380 ? S 16:01 0:00 \_ sh /opt/scripts/V1.0/utils/install.sh THE_PACKAGE").rpm()
letterOrDigit方法在找到0.0
时无效。
e.g。
root 26250 0.0 0.0 108208 1380 ? S 16:01 0:00 ...
anything
内置规则也不起作用,我收到此错误:
Parse error at line 2, column 0: end of input. trail: [anything]
任何想法?
- 更新 -
我设法让它像这样工作,但它看起来很难看,我希望我能用anything
规则简化所有特殊字符检查:
x = parsley.makeGrammar("""
a_dot = exactly('.')
a_colon = exactly(':')
a_question_mark = exactly('?') ws
the_activation_engine_script = '\_ sh /opt/scripts/V1.0/utils/install.sh'
anything_followed_by_a_space = <letterOrDigit+> ws|a_dot|a_question_mark|a_colon
rpm = anything_followed_by_a_space{18} the_activation_engine_script ws <anything+>:name_of_the_rpm -> (name_of_the_rpm)
""", {})
print x("root 26250 0.0 0.0 108208 1380 ? S 16:01 0:00 \_ sh /opt/scripts/V1.0/utils/install.sh THE_PACKAGE").rpm()
输出:
>>>
THE_PACKAGE