java 如何在 Mule Dataweave 转换中使用正则表达式替换特殊字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40214908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to replace special character using regex in Mule Dataweave transformation?
提问by Aditya
Suppose I have an XML file of details of employee such as id, name and address and now I want to convert it into JSON file and before the conversation I want to replace specified special character (- , /) with blank space in address field of json document
假设我有一个包含员工详细信息(例如 ID、姓名和地址)的 XML 文件,现在我想将其转换为 JSON 文件,并且在对话之前我想用地址字段中的空格替换指定的特殊字符 (-, /) json文件
below are my Dataweave transformation code
下面是我的Dataweave 转换代码
%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> {
Id: payload01 .d as :string,
Name: payload01.Name as :string,
Address: payload01.Address replace /(?)/ with " "
})
So what should I write within replace /()/ function to replace specials character ,-and /with blank space?
那么我应该在 replace /()/ 函数中写什么来用空格替换特殊字符、-和/?
回答by user3928757
Please try the following code
请尝试以下代码
Address: payload01.Address replace /([\-\,\/])/ with " "