ruby - 如何使字母小写,除非它跟在逗号或正则表达式的斜杠后面

问题描述

我正在尝试使用 ruby​​ 代码中的 MysqL2 gem 从 MysqL 表中清理一组名称,然后将清理过的名称添加到表中的新列中。除了一种情况:Lowercasing all words,unless they come after a slash or after a comma or in parentheses 外,我能够进行清洁。这是一段示例代码

def cleaning_names(client)
  q = "SELECT column_of_names FROM original_table;"
  names = client.query(q)
  names.map do |name|
    clean_name = "#{name["column_of_names"]"
  end
end

我使用了多个 gsub 来完成剩下的清理工作,但我不知道如何使用正则表达式(可能在 gsub 中)来小写字母,或者如果它们在斜杠或逗号之后。

例如,我想要的名称之一是:'County Clerk/DeKalb County' 变为 ‘DeKalb County clerk’"1st circuit judge,Circuit Court" 变为 "1st circuit judge (Circuit Court)"。我的代码修复了顺序,但没有正确大写。

谢谢:-)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)