Regex pattern or string manipulation

Hello Guys,

I have following string I need to capture the amount before the string and after the string. The string is fixed. Please consider white spaces.

1234 I FEEL HAPPPY 123456.23

Thanks in advance

Hi @RPA2,
Regex for first part -> https://regex101.com/r/kcqrxU/1 - then use index 0 for it
Regex for second part -> https://regex101.com/r/qpDvhP/1

1 Like

Thanks Pablito for quick reply.

I have to consider the fixed string also. Because only that is the key object I have form the entire text file. So the text file consists many numbers and amounts and if I use only number reading pattern it will come up with all the numbers in the text file which I don’t want.

So we have to create regex that can consider the fixed string.

Please give more example. From mentioned string you wanted to extract number before and after the text what actually I’ve done.

Hello Pablito,

I am using this sort of text file. from which I am getting two values

1 BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF 123.456

so I am capturing 1 and 123.456

Thanks

Buddy @RPA2
kindly follow the below steps that could resolve your issue buddy

  1. once the above image or pdf or word is read and obtained as a string variable named out_text, use an assign activity to split them into array of lines
    out_string_array = out_text.Split(Environment.Newline.ToArray())
    this would give us array of string as output, so the out_string_array is of type string array
  2. then use a for each loop to iterate through each line of array and pass the variable out_string_array as input to the loop and change the type argument as string in the for each loop property
  3. inside the for each loop use a if condition like this
    item.ToString.Contains(“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”)
    if this condition gets passed, go for THEN part of if condition and use a assign activity like this buddy
    out_value_1 = item.split(“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”)(0).ToString.Trim
    out_value_2 = item.split(“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”)(1).ToString.Trim

so the
out_value_1 = 1
out_value_2 = 123.456

Thats all buddy you are done
Kindly try this and let know buddy @RPA2
Cheers

2 Likes

Hello Palaniyappan,

I am getting this error. item_string is my item for For Each.

Buddy @RPA2
waht was the error buddy
can you get your mouse to the blue symbol at the right top of the activity buddy

Cheers

Hi @RPA2

Try using below code

Value1 (String) = item.split({“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”},StringSplitOptions.None)(0).ToString.Trim

Value2 (String) = item.split({“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”},StringSplitOptions.None)(1).ToString.Trim

Hey @RPA2

You can use Below Regex pattern for this - [0-9]*\.?[0-9]+

Reference Link - https://regex101.com/r/kcqrxU/2

Sample - RegexPatternForStringOperationSample.xaml (6.0 KB)

Regards…!!
Aksh

Hello Akshay Regex bulder is 2019 version while I have 2018.

Hey @RPA2

Nothing will affect just use pattern in Pattern property. and pass input string and output variable

Regards…!!
Aksh

Annotation%20

Hello ALL RPA GURUS,

Thanks you so much for your efforts in resolving this issue.

I am uploading the screenshot how I did it so anyone can take a look if need.

Buddy it should be like this @RPA2

you were almost right, but need some corrections buddy

item_string.Split(“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”,StringSplitOptions.None)(0).ToString.Trim

item_string.Split(“BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF”,StringSplitOptions.None)(1).ToString.Trim

Cheers @RPA2

Hi

If you just want to use a Regular expression to get the values then you can use the ones below:

1 BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF 123.456

To get the first number (1)
\d+(?=(\D+ \d+\.\d+))

To get the string (BANK DRAFT PAYMENTS APPLIED FOR A TOTAL OF)
(?<=\d+ )\D+(?=( \d+\.\d+))

To get the second number (123.456)
(?<=\d+ \D+ )\d+\.\d+

Using RegEx is considerably less complicated than using string functions.

Hope this helps