正则表达式拒绝友好网址中的特殊挪威字母 - modx
我正在使用 modx Revolution 开发一个页面。它是一个完整的 cms,具有许多内置功能。如果我在管理器中创建一个页面,它会自动为我生成一个指向该页面的友好 URL。
问题是,这并没有否认挪威的特殊字符 æøå(和大写 ÆØÅ)。
系统有一个内置的正则表达式模式来去除大多数不良字符的 url,但我也需要去除 æøå 和 ÆØÅ 的表达式。
该模式如下所示:
/[\0\x0B\t\n\r\f\a&=+%#<>"~:`@\?\[\]\{\}\|\^'\\]/
任何人都可以使用他们神奇的正则表达式知识来包含这 6 个字母吗?我对正则表达式完全陌生,仅仅在其中添加字母似乎不起作用。
PS:请不要在这里使用常见的“嘘,不要使用正则表达式”。该模式的存在是有原因的,如果我们必须升级 modx(这很可能迟早会发生),我不想弄乱核心。
I'm developing a page using modx revolution. It's a complete cms with a lot of built in functions. If I create a page in the manager it will automatically produce a friendly url for me pointing to that page.
The problem is that is does not deny the special characters we have in Norway, æøå (and uppercase ÆØÅ).
The system got a built in regex-pattern to strip the url for most bad characters, but I need the experession to strip æøå and ÆØÅ too.
The pattern looks like this:
/[\0\x0B\t\n\r\f\a&=+%#<>"~:`@\?\[\]\{\}\|\^'\\]/
Can anyone use their magic regex-knowledge to include these 6 letters? I am totally green at regex, and simply adding the letters in there did not seem to work.
PS: Please don't use the common "boo, don't use regex for this" here. The pattern is there for a reason, and i don't want to mess around with the core if we have to upgrade modx (which is pretty likely to happen sooner or later).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 Unicode。我不知道modx,但由于它是用php编写的,我希望它使用php preg正则表达式。
u
修饰符告诉 php 使用 unicode 匹配模式,然后它将正则表达式解释为 unicode 字符串。\x{00C6}
是 Unicode 字符 Æ请自行检查其他字符的代码,以确保我在查找时没有出错。
有关 php 中 unicode 的用法,请参阅 regular-expression.info
Unicode.org 代码点
Try to use Unicode. I don't know modx, but since its written in php, I hope it uses php preg regular expressions.
The
u
modifier tells php to use unicode matching mode, it then interprets the regular expression as unicode string.\x{00C6}
is the Unicode character ÆPlease check the code of the other characters by yourself to ensure I didn't made a mistake while looking them up.
See regular-expression.info for the unicode usage in php
Unicode.org for the code point
MODX 实际上有一个系统设置,您可以在其中定义自定义音译类:http://rtfm.modx。 com/display/revolution20/Friendly_alias_translit_class
但是,文档对于如何实现这一点有点稀疏。有一个由核心开发人员构建的现有软件包,支持德语和俄语的别名音译,但您可以轻松地将挪威语或任何其他语言添加到其配置中:
http://modx.com/extras/package/translit
MODX actually has a system setting where you can define a custom transliteration class: http://rtfm.modx.com/display/revolution20/friendly_alias_translit_class
However the docs are a bit sparse on how you might implement this. There is an existing package built by one of the core developers which supports alias transliteration for German and Russian, but you can easily add Norwegian or any other language to its configuration:
http://modx.com/extras/package/translit