Please help clarify my regex pattern

Posted by Dmitriy Sosunov on Stack Overflow See other posts from Stack Overflow or by Dmitriy Sosunov
Published on 2011-01-14T02:42:17Z Indexed on 2011/01/14 2:53 UTC
Read the original article Hit count: 249

Filed under:

I have the following string:

<script>m('02:29:1467301/>Sender1*>some text message?<<02:29:13625N1/>Sender2*>Recipient2: another message??<>A<<02:29:1393100=>User1*|0User2*|%></B><<','');</script>

N.B. messages are separated by <<

I need extract from message the following parts:
1. Time
2. Sender
3. Recipient
4. Text

Recipient may being defined or not, this field is optional.

I do this by the following pattern:
(?<message>(?<time>\d{1,2}:\d{1,2}:[0-9a-z]+)/>(?<messageData>(?<sender>.+?)\*>(.+?)))<<

But, I cannot extract recipient separately from the message text.
(?<message>(?<time>\d{1,2}:\d{1,2}:[0-9a-z]+)/>(?<messageData>(?<sender>.+?)\*>(((?<recipient>.+?):){0,1}(?<messageText>.+?))))<<

Please help correct my pattern.

© Stack Overflow or respective owner

Related posts about regex