on 09-23-2016 5:47 PM
Hi All,
I need to find lower case alphabets in a string and replace to blanks
I try to use regex_replace like below
regex_replace(table1.field,'\\[a-z\\]','')
But this does not work correctly for all records
I get junk characters appearing in the field
can you please help me with the correct syntax
(some issue with the slash I use for [a-z])
Hi,
Please use replace substr function
Regards
Krishna mohan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dirk,
Please see thread https://scn.sap.com/thread/3860280
(where another person has faced the same issue like me - appearance of junk characters)
I can see the translate function works only for cases that satisfy the condition (strings that have lower case alphabets), otherwise it creates junk characters for records where there are no lower case values
hence I am trying to use match_regex or match pattern in a IF ELSE condition and then apply translate (only for records that have lower case in the field)
ifthenelse(match_pattern(Query.Field,'[x]*')>0),translate(Query.Field,,'abcdefghijklmnopqrstuvwxyz',''),Query.Field,)
ifthenelse(match_regex(Query.Field,'[a-z]*',null)>0),translate(Query.Field,,'abcdefghijklmnopqrstuvwxyz',''),Query.Field,)
but both are not working . Can you please let us know the string pattern to be used for lower case alphabets ?
for both match_pattern and match_regex functions ?
Thanks in advance
Hi Dirk,
I got an alternate option for the code (instead of Regex_replace with pattern search and translate). I created a custom function with unicode characters in regex_replace and called in my flow.
This works perfectly fine without the occurrence of junk values
$Input_String = regex_replace($Input_String,'\\[^\u0061\u0062-\u0079\u006A-\u006F\u0070-\u0079\u007A\\]','');
Return $Input_String;
------------Thank you Dirk and everyone for your help !!--------------------------
(I feel there is some issue with our DS version since it was causing junk values for Regex_replace with pattern search and translate functions)
I can see the translate function works only for cases that satisfy the condition (strings that have lower case alphabets), otherwise it creates junk characters for records where there are no lower case values
This is definitely not true, because it works fine for me .
Try replace_substr( translate(table1.field,'abcdefghijklmnopqrstuvwxyz',' '), ' ',''))
By replacing lowercase characters by a space, you won't shorten the string length and no junk can appear. Then get rid of all spaces with replace_substr.
Simply use translate built-in function:
translate(table1.field,'abcdefghijklmnopqrstuvwxyz','')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I suspect values in table1.field has the junk characters. Your regex code looks fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Malini,
Have got a different approach using UDT transform. Hope it helps.
1. Drop a Base_userdefined transform i.e. UDT in the DS workspace
2. In the input section drop the field you want to process. In my case it was STRING. Refer screenshot:
3. Now, in the options tab click the Edit Options button -> Click Per record mode -> Then select Python Expression editor -> Finally click Python Launch Python editor
Type the below code and it should work.
Validate then Apply and in the Output tab select the output field created by us.
Execute the job.
Regards- Santosh G.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.