irc 昵称的 PCRE 表达式?
大家好,我在使用 PCRE 正确制作 irc 昵称格式时遇到了一些问题。我不擅长 PCRE,我希望使用 PCRE / 正则表达式的人提供一些建议。 :)
我目前正在使用以下表达式: /^([^A-Za-z]{1})([^A-Za-z0-9-.]{0,32})$/< /代码> 我这样使用它:
preg_replace($regex, $replaceWith, $content)
我认为这意味着,从头到尾,任何不是 AZ、az 或 0 的字符-9为第一个字符,替换它。此后的任何字符(其中不是 AZ az、0-9、- 或 .)都将替换它。
如果有人可以提供帮助,那么您将提供很大的帮助。这是阻止我向新论坛软件发布聊天产品的唯一原因。 :/
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. :)
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)
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. :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我一直在使用以下正则表达式来检查 IRC 日志中的昵称:
在 preg_match 中使用它,如下所示:
我只是检查用户是否在线路上说了些什么,并且该线路不仅仅是加入/部分消息或昵称更改或类似的东西,但也很容易将其放入 preg_replace 中。
它根据 RFC 2812 第 2.3.1 节中的昵称规则匹配昵称,其中规定第一个字符必须是字母 (
a-zA-Z
) 或特殊字符 ([]{}^`|_\
),并且其余字符可以是字母、特殊字符、数字 (0-9
) 或连字符 (-
)。我根据 GTAnet 的NICKLEN=32
选择最大长度 32,而不是 RFC 的最大长度 9,因为许多网络似乎不遵循此标准。不同 IRC 网络之间的最大长度有所不同,因此请根据需要进行调整。I've been using the following regex to check for nicknames in my IRC logs:
using it in a preg_match like so:
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.
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'sNICKLEN=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.我不确定您要替换什么,但最好检查字符串是否与用户名匹配(而不是不匹配),如果不匹配则进行替换:
正则表达式表示:
I'm not sure what you're trying to replace with, but it'd be better to check if the string matches a username (instead of not matching) and then replace if it doesn't:
The regular expression says: