I use the following regular expression to check for aliases in IRC logs:
/<([a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}-]{1,31})>/
using it in preg_match, for example:
preg_match('/<([a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}-]{1,31})>/', $line)
I just check if the user said something in the line and the line was not just a message about the connection / part or bottom change or something like that, but it would be easy to put it in preg_replace too.
RFC 2812 2.3.1, , ( a-zA-Z) ([]{}^`|_\), , , (0-9) (-). 32 GTAnet NICKLEN=32 RFC max 9, , , . IRC, .