Skip to Content
Author's profile photo Former Member

Python code to keep only alphanumeric character

User_defined transform using Python script to keep only alpha numeric character

Input to the User_defined transform will be a Description field which will contain invalid character set as below.

Source

Name,Description

AAA,AAdesc@1

BBB,BBdesc$1

CCC,CCdesc*&1

DDD,DDKl@£$%[};’\D

Python script to remove the invalid character and keep only alphanumeric character

————————————————————————————————-

import re

var1 = locals()

var1[u’Description’] = record.GetField( u’Description’)

var1[u’Description’] = re.sub(“[^a-zA-Z0-9.]”,””,var1[u’Description’])

record.SetField(u’New_Description’,var1[u’Description’])

————————————————————————————————-

Target

DESCRIPTION,NEW_DESCRIPTION

AAdesc@1, AAdesc1

BBdesc$1, BBdesc1

CCdesc*&1, CCdesc1

DDKl@�$%[};’\D, DDKlD

Assigned tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kailas Kurup
      Kailas Kurup

      Thanks for this code. This was a requirement in one of our previous work. Will try this out.

      Author's profile photo Former Member
      Former Member

      Useful tip... . Thanks

      Author's profile photo Former Member
      Former Member

      Thanks Nishil...Was in search of this.. 🙂 really helped..

      Author's profile photo Former Member
      Former Member

      Very useful one

      Author's profile photo Former Member
      Former Member

      Good one..

      Author's profile photo Former Member
      Former Member

      Very Useful Nishil