英文:
Jolt replace text using regex
问题
以下是翻译好的部分:
Input
[
{
"name": "abc_google@gmail.com"
},
{
"name": "ayan.agrawal$1990@gmail.com"
}
]
Regex to be used
[^a-zA-Z0-9#$@]
Expected output:
[
{
"name": "abcgoogle@gmailcom"
},
{
"name": "ayanagrawal$1990@gmailcom"
}
]
英文:
I am trying to transform an input data where I need to transform/replace the text on the basis of a regex. Not able to find any examples on how this can be done in Jolt spec. Could someone please help on this. Thanks!
Input
[
{
"name": "abc_google@gmail.com"
},
{
"name": "ayan.agrawal$1990@gmail.com"
}
]
Regex to be used
[^a-zA-Z0-9#$@]
Expected output:
[
{
"name": "abcgoogle@gmailcom"
},
{
"name": "ayanagrawal$1990@gmailcom"
}
]
答案1
得分: 1
你不能使用正则表达式来完成这种方式。需要反其道而行之,例如,逐个渲染要移除的每个字符,然后可以通过连续应用split和join函数来实现,如下所示:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"nm0": "=split('.', @(1, name))",
"nm1": "=join('', @(1, nm0))",
"nm2": "=split('_', @(1, nm1))",
"name": "=join('', @(1, nm2))"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"nm*": ""
}
}
}
]
英文:
You cannot do in the way of doing with a regex. Need to think on the contrary manner, eg. rendering individually by each character to be removed, and we can do it by successively applying split and join functions such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"nm0": "=split('\\.',@(1,name))",
"nm1": "=join('',@(1,nm0))",
"nm2": "=split('_',@(1,nm1))",
"name": "=join('',@(1,nm2))"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"nm*": ""
}
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论