Remove alphabets from Alphanumeric field and restricting the length of digits to 5

rpadev1

New Member
Hi

I was trying multiple options using Regex. Replace for removing the Alphabets from Alphanumeric string and also restricting the overall length of Alphanumeric field to 5.
Few examples to explain result I want to achieve.

1. SAMY1456170911---- I want this field which has overall length of 14 to processed to give output as 14561
So basically i need the alphabets removed and also get only 5 digits from where last alphabet is located in that word

2. TOMY5617 -- The output should be 5617, since the alphabets are need to be removed and there are only 4 digits after alphabets so I need same.

3. CATY156710 - The output should be 15671, since alphabets are removed and I just need to restrict to 5 digits after alphabet.

I tried this format RIGHT(Regex.Replace(input, "[A-Za-z]", "") , 8) , but it doesnt get rid of Alphabets
 

Sundeep4sandy

New Member
Hello,

I had faced a similar issue, I used ->Utility String VBO->delete characters and in the characters to delete i used
"./\\_()\':,.;< >~!@#$%^&*|+=[]{}`~?a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z"

i hope this works
 

anisjolly

Administrator
Regex is a great way to achieve what you're looking to do. I'd recommend @otonx's reply as a perfect solution.

Do let us know if you solve your issue so we can mark this thread as solved.
 

rpadev1

New Member
I tried with above code in Code stage of Blueprism and it gave message, Regex is not identified and it gave error on Mid as well.
 

tgundhus

Member
His code is correct, but you will need to do a few tweaks..

1. Create an object with a code stage
1a. Create an text input named "input" (lowercase)
1b. Create an text output named "output" (lowercase)

2. In the code tab, paste following "output = Mid(Regex.Replace(input, "[^0-9]", ""), 1, 5)"

There you go!
How it works is that you send your data item storing your text e.x. "SAMY1456170911" as input.
The code will remove everything except digits from 0-9. Then look at the string you have left (1456170911) starting at position 1 (first char) and the 5 next and store that in the output variable.
 

rpadev1

New Member
@anisjolly .. I tried option with code stage and used System.Text.Regularexpressions for Regex along with replace option provided above which worked in achieving the desired result in Blue prism
 

Jiri.Hurda

New Member
I was not able to get the solution above working but it has lead me to this idea :)

General number extraction from text (=doesn't follow all aspects from the original issue described by rpadev1)

1. create code stage with input "InputText" and output "OutputNumber"
2. paste the code below:

Dim num As Boolean
Dim x As Integer
Dim i As Integer


x = Len(InputText)
i = 1


Do Until i = x + 1
num = IsNumeric(Mid(InputText, i, 1))


If num = True Then
OutputNumber = OutputNumber & Mid(InputText, i, 1)
End If


i = i + 1
Loop


Logic: code loops trough every character in the "InputText" and checks if the character is numeric (true / false). If True it concatenates numeric characters to OutputNumber"

If you set "if num = False then..." you can get a reversed function. To extract non-numeric characters from string (text + special characters). Or try "istext()" function to extract just text.
 
Last edited:
His code is correct, but you will need to do a few tweaks..

1. Create an object with a code stage
1a. Create an text input named "input" (lowercase)
1b. Create an text output named "output" (lowercase)

2. In the code tab, paste following "output = Mid(Regex.Replace(input, "[^0-9]", ""), 1, 5)"

There you go!
How it works is that you send your data item storing your text e.x. "SAMY1456170911" as input.
The code will remove everything except digits from 0-9. Then look at the string you have left (1456170911) starting at position 1 (first char) and the 5 next and store that in the output variable.


Hello friend as you said i did but i didnt get output please guide me.
View attachment 1576683084906.pngView attachment 1576683158450.png
 
Hello,

I had faced a similar issue, I used ->Utility String VBO->delete characters and in the characters to delete i used
"./\\_()\':,.;< >~!@#$%^&*|+=[]{}`~?a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z"

i hope this works

Awesome brother, its works fine thanks a lot
 
Top