【问题标题】:Parse a skype log解析 Skype 日志
【发布时间】:2012-07-29 22:16:50
【问题描述】:

我需要解析一个 Skype 日志,获取所有通话时长并将它们相加,然后找出整个聊天记录的通话总时长。

示例:

[2012 年 3 月 12 日上午 11:36:44] * 通话结束,持续时间 21:33 *

我认为我需要将 preg_match 与正确的正则表达式一起使用。如果可以同时将实际时间戳存储在数组中,那就更好了。

我认为我真正难过的是获取通话时间所需的实际正则表达式规则。

【问题讨论】:

  • 是否会抓取一行中的最后 7 个字符来删除空格和 asterix 工作?
  • @Dagon 不,可能会有一个小时字段。
  • 发布“持续时间”的所有内容,然后进行一些清理
  • 实际上是 * 操作格式吗?还是实际文件?

标签: php regex skype


【解决方案1】:

你可以用这个:

 \*.+?([0-9]+:){1,2}([0-9]+)

然后它可以捕获第一个 * 之后的 HH:MM:SS 和 MM:SS。

【讨论】:

  • 不会把时间戳抓到 ?
【解决方案2】:

试试这个

(?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, as many times as possible, giving back as needed (greedy)
[*]                # Match the character “*”
\s                 # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
   *                  # Between zero and unlimited times, as many times as possible, 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, as many times as possible, 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, as many times as possible, giving back as needed (greedy)
   ){2,3}             # Between 2 and 3 times, as many times as possible, giving back as needed (greedy)
)
\s                 # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
   *                  # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
[*]                # Match the character “*”
"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-23
    • 2016-01-09
    • 2014-11-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多