php – 解析skype日志
我需要解析一个Skype日志,抓住所有通话时长并添加它们,并找出整个聊天记录的总呼叫持续时间. 样品: [3/12/2012 11:36:44 AM] *通话结束,持续时间21:33 * 我想我需要使用preg_match和正确的正则表达式.如果可以在更好的同时将实际时间戳存储在数组中. 我认为我真正难以理解的是实际的正则表达式规则,只需要获取呼叫持续时间. 试试这个 (?i)\[(?P<time
我需要解析一个Skype日志,抓住所有通话时长并添加它们,并找出整个聊天记录的总呼叫持续时间.
样品:
[3/12/2012 11:36:44 AM] *通话结束,持续时间21:33 *
我想我需要使用preg_match和正确的正则表达式.如果可以在更好的同时将实际时间戳存储在数组中.
我认为我真正难以理解的是实际的正则表达式规则,只需要获取呼叫持续时间.
解决方法
试试这个
(?i)\[(?P<time_stamp>[^[]+)\]\s*[*]\s*[a-z,]+(?P<duration>(?:\d{2}:?){2,3})\s*[*]
说明
"
(?i) # Match the remainder of the regex with the options: case insensitive (i)
\[ # Match the character “[” literally
(?P<time_stamp> # Match the regular expression below and capture its match into backreference with name “time_stamp”
[^[] # Match any character that is NOT a “[”
+ # Between one and unlimited times,as many times as possible,giving back as needed (greedy)
)
\] # Match the character “]” literally
\s # Match a single character that is a “whitespace character” (spaces,tabs,and line breaks)
* # Between zero and unlimited times,giving back as needed (greedy)
[*] # Match the character “*”
\s # Match a single character that is a “whitespace character” (spaces,giving back as needed (greedy)
[a-z,] # Match a single character present in the list below
# A character in the range between “a” and “z”
# One of the characters “,”
+ # Between one and unlimited times,giving back as needed (greedy)
(?P<duration> # Match the regular expression below and capture its match into backreference with name “duration”
(?: # Match the regular expression below
\d # Match a single digit 0..9
{2} # Exactly 2 times
: # Match the character “:” literally
? # Between zero and one times,giving back as needed (greedy)
){2,3} # Between 2 and 3 times,giving back as needed (greedy)
)
\s # Match a single character that is a “whitespace character” (spaces,giving back as needed (greedy)
[*] # Match the character “*”
"
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。