Pcre expression for irc aliases?

Hi guys, I have a few problems using PCRE to properly compose the irc proxy format. I am not good at PCRE and I would like some suggestions from those using PCRE / regex. :)

I am currently using this expression: /^([^A-Za-z]{1})([^A-Za-z0-9-.]{0,32})$/ I am using it as such:preg_replace($regex, $replaceWith, $content)

I assumed that this means, from front to end, any characters that are not AZ, az or 0-9 for the first character replace it. Any characters after that in which no az az, 0-9, -, or., Replace it.

If someone can help, you would really help. This is the only thing that prevents me from releasing a chat product on the new forum software.: /

+1
source share
2 answers

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, .

+1

, , , ( ), , :

$regex = '/^[a-z][a-z0-9.-]{0,32}$/i';
if (!preg_match($regex, $content))
{
  // do your replace here
}

:

^                   # Beginning of string
  [a-z]             # Match a single a-z
  [a-z0-9.-]{0,32}  # Match between 0 and 32 occurances of a-z, 0-9, . or -
$                   # End of string
/i                  # Make the pattern case-insensitive
0

All Articles