cancel
Showing results for 
Search instead for 
Did you mean: 

Find lower case in a string

Former Member
0 Kudos

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])

Accepted Solutions (0)

Answers (3)

Answers (3)

krishnamohan_corp9
Participant
0 Kudos

Hi,

Please use replace substr function

Regards

Krishna mohan

former_member187605
Active Contributor
0 Kudos

Don't post incorrect answers, that's so confusing!

Replace_substr takes an input string, replaces each occurrence of a specified substring with a specified replacement, and returns the result.

How do you want to achieve OP's required results??? Convince me with an example .

Former Member
0 Kudos

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

Former Member
0 Kudos

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)

former_member187605
Active Contributor
0 Kudos
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.

former_member187605
Active Contributor
0 Kudos

Simply use translate built-in function:

translate(table1.field,'abcdefghijklmnopqrstuvwxyz','')

Former Member
0 Kudos

Hi Dirk,

My requirement is to remove the lower case in the string

Eg : L0OeEEEII1FR

should be converted to   L0OEEEII1FR

(the lower case e needs to be removed)

but when I use translate (the code you had provided , I get junk characters)

Is there any there alternate solution ?

former_member187605
Active Contributor
0 Kudos

Then there's some junk in your source data. It works fine for me:

print(translate('L0OeEEEII1FR','abcdefghijklmnopqrstuvwxyz',''));

results in:

6728    8436    PRINTFN    26.09.2016 18:00:29    L0OEEEII1FR

mageshwaran_subramanian
Active Contributor
0 Kudos

I suspect values in table1.field has the junk characters. Your regex code looks fine.

Former Member
0 Kudos

H Mahesh,

Thank you for your response. Can you please tell me using single slash Is correct or 2 slashes are correct?

Eg

regex_replace(table1.field,'\\[a-z\\]','')

is correct ? Or

regex_replace(table1.field,'\[a-z\]','')

Message was edited by: Malini L

santossh
Active Participant
0 Kudos

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.