Hi Team,
Please find Python Regex .How to convert this regex to Data weave code? Consider that the input is List of string; just a few examples are mentioned.
Input : ["R525-80",
"RPSLCASP000003",
"R212-25",
"R212-1",
"R212-51",
"RPSLCASP000002",
"R212-2",
"I21-71",
"IPUSMILW000007",
"I30-28",
"I21-72",
"MKE-001-EK01",
"GRB-701-HS01",
"IPUSMILW000006",
"I21-70",
"I21-62",
"I21-9999",
"I21-0",
"I21-999",
"I21-998",
"I21-9998",
"IPUSMILW000011",
"I21-2",
"IPUSMILW000014"]
Input:I7-7 ---------> OutPut: 070007
Pattern Replace
('^I(\d{1})-(\d{1}$)', r'0\g<1>000\g<2>')
Input:I2-41 --------> OutPut: 020041
('^I(\d{1})-(\d{2}$)', r'0\g<1>00\g<2>')
Input:I2-418 -------> OutPut: 020418
('^I(\d{1})-(\w{1})(\d{2}$)', r'0\g<1>0\g<2>\g<3>')
Input:I1-1510 ------> OutPut: 011510
('^I(\d{1})-(\d{4}$)', r'0\g<1>\g<2>')
Input:I79-8 --------> OutPut: 790008
('^I(\d{2})-(\d{1}$)', r'\g<1>000\g<2>')
Input:I25-10 -------> OutPut: 250010
('^I(\d{2})-(\d{2}$)', r'\g<1>00\g<2>')
Input:I61-218 ------> OutPut: 610218
('^I(\d{2})-(\w{1})(\d{2}$)', r'\g<1>0\g<2>\g<3>')
Input:I66-1525 -----> OutPut: 661525
('^I(\d{2})-(\d{4}$)', r'\g<1>\g<2>')
Input: R525-80 --> OUTPUT:RC525L80
('(^R)(\d+)-(\d+$)', r'\1C\2L\3')
Input: A30310300 --> OUTPUT: 30310300
('(^AP|^A|^PO|^P|^L)(\d{8}$)', r'\2')
Input:SEA-025-EK01 --> OUTPUT: SEA025EK01
('([a-zA-Z]{3})-([a-zA-Z0-9]{3})-([a-zA-Z0-9]{4})', r'\1\2\3')
Kindly advise or assist on achieving this in DataWave2.
Hi @Senthil Kumar , Try below snippet
%dw 2.0
output application/json
---
payload map ((item, index) -> item match {
case str matches /I(\d{1})-(\d{1}$)/ -> str[0] as String replace 'I' with '0' replace '-' with '000'
case str matches /I(\d{1})-(\d{2}$)/ -> str[0] as String replace 'I' with '0' replace '-' with '000'
else -> $
}
)
I have only added conditions for your first 2 examples. You can add similarly for others.
Regards,
Abhishek