In my Previous post(http://scn.sap.com/community/data-services/blog/2013/01/31/how-to-use-userdefined-transform-in-sap-bodsbusiness-object-data-services) I explained How to use User_defined Transform.
Here I am going to explain the Code which i used to Remove special Characters from input field
Follow up to step 5 (Create INPUT/OUTPUT fields.)of previous post and then
1. import package re(Regular Expression)
2. define Local variable
3. Fetch Input field value in Local Variable.
4. Apply function re.sub(“SEARCH EXPRESSION”,”REPLACE WITH”,”INPUT FIELD”)
re.sub:- re package name, sub function name used for search_replace .
“\W” :- Regular Expression indicates characters except Alpha Numeric [^0-9a-zA-Z_]
so in this example we are replacing all Non alphanumeric character with BLANK””.
5. Set Output field with modified value of local variable.
In this Example I replaced special character (character except [0-9a-zA-Z_]) using \W with BLANK.
Similarly we can use following Pattern and can replaced with our desired value …
Eg:- To Replace White Space with Underscore( _ ) , Expression will like this:- re.sub(“\s”,”_”,COLUMN NAME)
And you can use any range itself in expression like to replace Alphabet with 0 :-re.sub(“[a-zA-Z”,”0″,COLUMN NAME)
I would like to share more function of Regular expression using Python in further Posts.