IRC昵称的pcre表达式? [英] pcre expression for irc nicknames?

查看:66
本文介绍了IRC昵称的pcre表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在使用PCRE正确制作irc昵称格式时遇到了一些问题.我对PCRE不太满意,我很喜欢那些使用PCRE/regex的人的一些建议. :)

Hey guys, I'm having a few issues with using PCRE to make a irc nickname format correctly. I'm not good with PCRE, and I'd love some suggestions from those of you who do use PCRE / regex. :)

我当前正在使用以下表达式:/^([^A-Za-z]{1})([^A-Za-z0-9-.]{0,32})$/ 我这样使用它:preg_replace($regex, $replaceWith, $content)

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

我认为这意味着从头到尾,将第一个字符不是A-Z,a-z或0-9的任何字符替换.之后的任何字符(不是A-Z a-z,0-9,-或.)都将替换它.

I assumed this meant, starting from the front to the end, any characters that are not A-Z, a-z, or 0-9 for the first character, replace it. Any characters after that, in which are not A-Z a-z, 0-9, -, or ., replace it.

如果有人可以提供帮助,那么您将大有帮助.这是阻止我将聊天产品发布到新论坛软件的唯一方法. :/

If anyone could help, you would be helping out greatly. It's the only thing stopping me from releasing a chat product to a new forum software. :/

推荐答案

我一直在使用以下正则表达式检查IRC日志中的昵称:

I've been using the following regex to check for nicknames in my IRC logs:

/<([a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}-]{1,31})>/

像这样在preg_match中使用它:

using it in a preg_match like so:

preg_match('/<([a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}-]{1,31})>/', $line)

我只是检查用户是否在线路上说了些什么,而该线路不仅仅是联接/零件消息或昵称变更或类似的东西,但也很容易将其放入preg_replace中.

I simply check whether a user said something on the line and the line wasn't just a join/part message or nick change or something of the sort, but it would be easy to put it into a preg_replace too.

它根据 RFC 2812第2.3.1节中的昵称规则匹配昵称,表示第一个字符必须是字母(a-zA-Z)或特殊字符([]{}^`|_\),其余字符可以是字母,特殊字符,数字(0-9)或连字符().我根据GTAnet的NICKLEN=32选择了最大长度为32,而不是RFC的最大长度为9,因为许多网络似乎都不遵循此标准.最大长度因不同的IRC网络而异,因此请根据需要对其进行调整.

It matches the nicks according to the nickname rules in RFC 2812 Section 2.3.1, which state that the first character must be a letter (a-zA-Z) or special ([]{}^`|_\) and the rest of the characters may be letters, special, digits (0-9) or hyphens (-). I chose the max length of 32 based on GTAnet's NICKLEN=32 instead of the RFC's max length of 9, because many networks don't seem to follow this standard. The max length varies between different IRC networks so tweak it as required.

这篇关于IRC昵称的pcre表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆