JSONATA:较低木制的单词
我有一个由单词和标点符号组成的字符串,例如“接受数据保护条款 /条件(德语)”。我需要将其标准化为骆驼,以删除标点符号。
到目前为止,我最接近的尝试未能使单词骆驼,我只是设法使它们成为烤肉串或蛇case:
$normalizeId := function($str) <s:s> {
$str.$lowercase()
.$replace(/\s+/, '-')
.$replace(/[^-a-zA-Z0-9]+/, '')
};
I have a string consisting of words and punctuation, such as "Accept data protection terms / conditions (German)". I need to normalize that to camelcase, removing punctuation.
My closest attempt so far fails to camelcase the words, I only manage to make them into kebab-case or snake_case:
$normalizeId := function($str) <s:s> {
$str.$lowercase()
.$replace(/\s+/, '-')
.$replace(/[^-a-zA-Z0-9]+/, '')
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Anindya的答案适用于您的示例输入,但是如果
(German)
未大写,则会导致不正确的输出:链接到Playground
? cslokeslfenvvqmwfok33k6tpfecpufurkh8h1zvssrrfma1qspfjhxtpf1unxu% 2frdxhv1vjxntw0bzdezqvzdezqvzdezqvzdezqvzdezqvzbuyxdwigtwigtwigtwigtwigtwigt8ppnpnpnptnpnptnpntnptngngngng gugng gug 2g; 2x2uf
% "https://www.stedi.com/jsonata/playground?statev2=eJx9Uu1qwjAUfZVLKNi6pnVfP%2BY%2BQAaDvcKaDkJ7tYGahCSdU%2Bu7L22d4hzePyEn95x77iFZRqxqTIEkJvitDVorlPQX3k7aa38yMisK1A5K7jhooxwWzreAQ7O0kEKhZCk6xEK48BiXESOeGDIJEEjlkVps8L2E6TPMG9mzw8A6E8GTndoX2HadQ3Xw8dZVOoaDBuAXmrWrhFyAU1CrFZqCW4RxekpKgsNbGJ3pGdQ1LxC4XAMjurPU8H4DRmAlXAUc6D%2Bae16YZp%2BU082MfkzoQ36VxjCio%2FMxb0KWwOsaanQ%2BLPsrXXJbgZAwN0q6%2BJTmyycgNLgKh0buRRqt94t28CB3yR8Nk8i7Ooa9jGALwTJZGNVom03yJDhohhHszs2%2F1silH9yHVOPcKR997wjthdGMUEZ8HkMcu0cm%2F%2F6CMAj8W%2BQ%2FiGpv2tv2juQxuSf5D3ApvQA%3D" rel=" nofollow noreferrer“>链接到游乐场
Anindya's answer works for your example input, but if
(German)
was not capitalized, it would result in the incorrect output:Link to playground
This version would work and prevent that bug:
Link to playground
您应该针对前面有空间的字母,并使用此正则
/\ s(。)/
来大写。这是我的片段:(编辑
链接到操场
You should target the letters which has a space in front, and capitalize them by using this regex
/\s(.)/
.Here is my snippet: (Edited
Link to playground