4

スカイプ ログを解析し、すべての通話時間を取得して合計し、チャット履歴全体の合計通話時間を調べる必要があります。

サンプル:

[2012 年 3 月 12 日 11:36:44 AM] * 通話終了、通話時間 21:33 *

適切な正規表現で preg_match を使用する必要があると思います。実際のタイムスタンプを同時に配列に格納できる場合は、それがより良いでしょう。

私が本当に困惑しているのは、通話時間だけを取得するために必要な実際の正規表現ルールだと思います。

4

2 に答える 2

1

これを試して

(?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 “*”
"
于 2012-08-01T05:31:46.167 に答える
0

これを使用できます:

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

次に、最初の の後に来る HH:MM:SS と MM:SS の両方をキャッチでき*ます。

于 2012-08-01T03:24:02.490 に答える