ruby 1.8.7 中的正则表达式将检测 4 字节 Unicode 字符

发布于 2024-12-09 17:04:13 字数 255 浏览 4 评论 0原文

谁能告诉我如何在 ruby​​ 1.8.7 中编写 ruby​​ 正则表达式来检测 4 字节 unicode 字符(特别是表情符号)的存在?我正在尝试处理 mysql 默认情况下不这样做的事实,允许您存储 4 字节 emoji unicode 字符,现在 iOS 5 使用。

谢谢!

Can anyone tell me how I would write a ruby regexp in ruby 1.8.7 to detect the presence of a 4-byte unicode character (specifically the emoji)? I am trying to handle the fact that mysql does not, by default, allow you to store 4-byte emoji unicode characters, now in use by iOS 5.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

硬不硬你别怂 2024-12-16 17:04:13

这似乎与表示表情符号的四个字节中的前两个字节匹配。这是在 ruby​​ 1.8.7 中运行的。

str.match(/\360\237/)

This appears to match the first two bytes of the four bytes that represent emoji. This is being run in ruby 1.8.7.

str.match(/\360\237/)
白日梦 2024-12-16 17:04:13

使用非阻塞在线方法更改表可能是可行的,例如 Maatkit 的 online-schema-change: http://www.percona.com/doc/percona-toolkit/pt-online-schema-change.html

来自文档:

简而言之,该工具的工作原理是创建一个临时表,该表是
原始表格的副本(被更改的表格)。 (临时
表不是像 CREATE TEMPORARY TABLE 那样创建的;我们称之为临时的
因为它最终取代了原始表。)临时表
表被更改,然后在原始表上定义触发器
捕获对其所做的更改并将其应用到临时表。这
保持两个表同步。然后所有行都从
原始表到临时表;这部分可能需要一段时间。什么时候
复制行后,使用 RENAME TABLE 交换两个表。
此时该表有两个副本:旧表
曾经是原始表,而新表曾经是
临时表,但现在与原始表同名。如果
指定 --drop-old-table ,则删除旧表。

Altering the table might be feasible using a non-blocking online approach, e.g. Maatkit's online-schema-change: http://www.percona.com/doc/percona-toolkit/pt-online-schema-change.html

From the docs:

In brief, this tool works by creating a temporary table which is a
copy of the original table (the one being altered). (The temporary
table is not created like CREATE TEMPORARY TABLE; we call it temporary
because it ultimately replaces the original table.) The temporary
table is altered, then triggers are defined on the original table to
capture changes made on it and apply them to the temporary table. This
keeps the two tables in sync. Then all rows are copied from the
original table to the temporary table; this part can take awhile. When
done copying rows, the two tables are swapped by using RENAME TABLE.
At this point there are two copies of the table: the old table which
used to be the original table, and the new table which used to be the
temporary table but now has the same name as the original table. If
--drop-old-table is specified, then the old table is dropped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文