Skip to main content
Add parsing tag. Correct title.
Source Link
rolfl
  • 97.5k
  • 17
  • 218
  • 418

Is my regex ok Using Regex to parse what I want or should I change anything to make it more ...a chat transcript

I need to classify each line as "announce, whisper or chat" once I have that sorted out I need to extract certain values to be processed.

Right now my regex is as follow:

var regex = new Regex(@"^\[(\d{2}:\d{2}:\d{2})\]\s*(?:(\[System Message\])?\s*<([^>]*)>|((.+) Whisper You :))\s*(.*)$");
  • Group 0 is the entire message.
  • Group 1 is the hour time of when the message was sent.
  • Group 2 is wether it was an announce or chat.
  • Group 3 is who sent the announce.
  • Group 4 is if it was a whisper or not.
  • Group 5 is who sent the whisper.
  • Group 6 is the sent message by the user or system.

Classify each line:

if 4 matchsmatches
 means it is a whisper
   else if 2 matchsmatches
     means it is an announce
       else
         normal chat

Should I change anything to my regex to make it more precise/accuratedaccurate on the matchsmatches ?

Sample data:

[02:33:03] John Whisper You :  Heya
[02:33:03] John Whisper You :  How is it going
[02:33:12] <John> [02:33:16] [System Message] bla bla
[02:33:39] <John> heya
[02:33:40] <John> hello :S
[02:33:57] <John> hi
[02:33:57] [System Message] <John> has left the room 
[02:33:57] [System Message] <John> has entered the room 

Is my regex ok to parse what I want or should I change anything to make it more ...

I need to classify each line as "announce, whisper or chat" once I have that sorted out I need to extract certain values to be processed.

Right now my regex is as follow:

var regex = new Regex(@"^\[(\d{2}:\d{2}:\d{2})\]\s*(?:(\[System Message\])?\s*<([^>]*)>|((.+) Whisper You :))\s*(.*)$");
  • Group 0 is the entire message.
  • Group 1 is the hour time of when the message was sent.
  • Group 2 is wether it was an announce or chat.
  • Group 3 is who sent the announce.
  • Group 4 is if it was a whisper or not.
  • Group 5 is who sent the whisper.
  • Group 6 is the sent message by the user or system.

Classify each line:

if 4 matchs
 means it is a whisper
   else if 2 matchs
     means it is an announce
       else
         normal chat

Should I change anything to my regex to make it more precise/accurated on the matchs ?

Sample data:

[02:33:03] John Whisper You :  Heya
[02:33:03] John Whisper You :  How is it going
[02:33:12] <John> [02:33:16] [System Message] bla bla
[02:33:39] <John> heya
[02:33:40] <John> hello :S
[02:33:57] <John> hi
[02:33:57] [System Message] <John> has left the room 
[02:33:57] [System Message] <John> has entered the room 

Using Regex to parse a chat transcript

I need to classify each line as "announce, whisper or chat" once I have that sorted out I need to extract certain values to be processed.

Right now my regex is as follow:

var regex = new Regex(@"^\[(\d{2}:\d{2}:\d{2})\]\s*(?:(\[System Message\])?\s*<([^>]*)>|((.+) Whisper You :))\s*(.*)$");
  • Group 0 is the entire message.
  • Group 1 is the hour time of when the message was sent.
  • Group 2 is wether it was an announce or chat.
  • Group 3 is who sent the announce.
  • Group 4 is if it was a whisper or not.
  • Group 5 is who sent the whisper.
  • Group 6 is the sent message by the user or system.

Classify each line:

if 4 matches
 means it is a whisper
   else if 2 matches
     means it is an announce
       else
         normal chat

Should I change anything to my regex to make it more precise/accurate on the matches ?

Sample data:

[02:33:03] John Whisper You :  Heya
[02:33:03] John Whisper You :  How is it going
[02:33:12] <John> [02:33:16] [System Message] bla bla
[02:33:39] <John> heya
[02:33:40] <John> hello :S
[02:33:57] <John> hi
[02:33:57] [System Message] <John> has left the room 
[02:33:57] [System Message] <John> has entered the room 
Tweeted twitter.com/#!/StackCodeReview/status/75895414099951617
Source Link
Prix
  • 165
  • 6

Is my regex ok to parse what I want or should I change anything to make it more ...

I need to classify each line as "announce, whisper or chat" once I have that sorted out I need to extract certain values to be processed.

Right now my regex is as follow:

var regex = new Regex(@"^\[(\d{2}:\d{2}:\d{2})\]\s*(?:(\[System Message\])?\s*<([^>]*)>|((.+) Whisper You :))\s*(.*)$");
  • Group 0 is the entire message.
  • Group 1 is the hour time of when the message was sent.
  • Group 2 is wether it was an announce or chat.
  • Group 3 is who sent the announce.
  • Group 4 is if it was a whisper or not.
  • Group 5 is who sent the whisper.
  • Group 6 is the sent message by the user or system.

Classify each line:

if 4 matchs
 means it is a whisper
   else if 2 matchs
     means it is an announce
       else
         normal chat

Should I change anything to my regex to make it more precise/accurated on the matchs ?

Sample data:

[02:33:03] John Whisper You :  Heya
[02:33:03] John Whisper You :  How is it going
[02:33:12] <John> [02:33:16] [System Message] bla bla
[02:33:39] <John> heya
[02:33:40] <John> hello :S
[02:33:57] <John> hi
[02:33:57] [System Message] <John> has left the room 
[02:33:57] [System Message] <John> has entered the room