Transform Node
I have a set of data with more 2K+ and it contains mix of letter and numbers as it show on the sample. I need to emit the number from it and still kept the original by using the Transform node or any possible way. For example, ad71296 --> the NewField should contain = 71296...
ad71296 |
sulieti2018 |
ad37010 |
ad21301 |
ad22068 |
pad21860 |
-
As John's reply shows - there are several ways this can be done. Here is an example using regular expressions.
## ConfigureFields Script
import re
#Configure all fields from input 'in1' to be mapped
#to the corresponding fields on the output 'out1'
out1 += in1
out1.DigitsOnly = unicode
pattern = r'^([a-zA-Z]+)(\d+)$'## ProcessRecords Script
#Copy all fields from input 'in1' to the corresponding output fields
#in output 'out1'. Copies the values of the fields that have been setup
#in the mapping defined in the ConfigureFields property
out1 += in1
if fields.Data == Null or fields.Data == "":
out1.DigitsOnly = Null
else:
match = re.match(pattern, fields.Data)
if match:
out1.DigitsOnly = match.group(2)
else:
out1.DigitsOnly = Null
Please sign in to leave a comment.
Comments
3 comments