sql - 正则表达式在 Redshift 中将 CamelCase 转换为蛇形案例
问题描述
我正在尝试将 CamelCase 转换为蛇形大小写或regex
在 SQL (AWS Redshift) 中使用分隔符分隔。所以像
regexp_replace(MyString, '([A-Z]+)', '-$1')
除了我需要不在字符串的开头指定。马上,
MyString
->-my-string
而不是my-string
.
我该怎么做呢?
解决方案
Match and capture any char before the uppercase letters, and restore it using another backreference in the replacement pattern:
regexp_replace(MyString, '(.)([A-Z]+)', '$1-$2')
^^^ ^^^^^
See the regex demo.
I understand you already LOWER
the result after the regex replacement.
推荐阅读
- c# - 如何删除从 Excel 文件导入的 WPF DataGrid 中的多个空白行
- sql-server - 从存储过程 ASP Classic 返回值
- r - 使用 for 循环在 R 中进行模拟
- python-3.x - 从两个相同大小的单独列表向字典添加键和值
- javascript - 为什么在这种情况下我必须使用扩展语法?
- bash - 为什么算法表达式结果会被截断?
- rust - &Vec 赋值借用
- javascript - 如何使用 react-native onPress 更改变量
- apache-poi - Apache poi Excel write() 花费了太多时间
- python - y 轴上的百分比