I have a log message like this
我有这样的日志消息
(12/12/2013 03:12:21 PM) 06:21:22.234 - 5463723 : ##Some Message##
(12/12/2013 03:12:21 PM)06:21:22.234 - 5463723:## Some message ##
i need to write a regular expression to extract Some Message from above log record. How can i write a regular expression to extract the required words out. Note: I am using python language to parse the log files..
我需要编写一个正则表达式来从上面的日志记录中提取一些消息。如何编写正则表达式来提取所需的单词。注意:我使用python语言来解析日志文件。
2 个解决方案
#2
0
You don't even need a regex for that:
你甚至不需要正则表达式:
line.split("##", 2)[1]
This will split the line on the ##
character combination, and then return the second element. The first element is everything before the first ##
, and the second will then be the text between them.
这将拆分##字符组合上的行,然后返回第二个元素。第一个元素是第一个##之前的所有元素,第二个元素是它们之间的文本。
#1
#2
0
You don't even need a regex for that:
你甚至不需要正则表达式:
line.split("##", 2)[1]
This will split the line on the ##
character combination, and then return the second element. The first element is everything before the first ##
, and the second will then be the text between them.
这将拆分##字符组合上的行,然后返回第二个元素。第一个元素是第一个##之前的所有元素,第二个元素是它们之间的文本。