Copy text into a variable even if the field is empty

Hi, I have a text that contains, for example:

  1. Name:
  2. Surname:
  3. Address:
    I wanted the robot to copy text after “:” for each point and so that I could have the name in one variable, the surname in another, etc.
    Everything works for me until a field after “:” is empty, then it starts reading the data incorrectly.
    I would like it to read point by point, despite the empty field, after the “:” sign - what am I doing wrong?

Hi there,

please share a sample of the input text

Hello,

Name: Alex
Surname: XYZ
Address:
Phone number: 555-444-444

Some examples. I need each piece of information after “:” separately. These are employee data, but some fields, such as here and the address, are empty.

Hi @sullivanne

Try this

(?<=:)(.*)

image

image

Regards,

2 Likes

I can see you use RegEx to parse the input data.
So I guess you need to correct your RegEx to match your needs.
The best is use one of online RegEx testers where you could simulate different scenarios and validate result.

Cheers

1 Like

I would suggest you separate your variables

create a string variable for Name and use assign activity like below:


System.Text.RegularExpressions.Regex.Match(strInputText, "(?<=Name:\s).*").ToString

Do the same for surname, address and phone number, You only need to change the anchor on the regex eg for surname it will be

System.Text.RegularExpressions.Regex.Match(strInputText, "(?<=Surname:\s).*").ToString

this way its simple and easier to maintain.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.