How to extract usernames (with variable number of users) from between text

Hello,
Using UiPath I need to extract the name of all users from between the text - each user must be assigned in a separate column in DataTable. The number of users varies - there may be one or a dozen. Below is an example of text that I can extract from the application:
“Select the right Service: Project CreationEnter Project Administrator: User1Enter Project Administrator: User2Enter Project Administrator: User3Enter Project Category: None”
I need to extract all project administrators into DataTable:
|Column 1|
|User1|
|User2|
|User3|

The number of users may vary. Then the text will look like this.
“Select the right Service: Project CreationEnter Project Administrator: User1Enter Project Category: None”
Then i need to extract only “User1” to DT.
Could you please help?
Best Regards,
Damian

Hello Damian,

Please find below steps useful:

  1. Initialize Variables:
  • Initialize a variable named inputText to store the text you want to extract from.
  • Initialize a DataTable variable named userDataTable to store the extracted user names.
  1. Use Matches Activity:
  • Use the Matches activity to extract all occurrences of user names from the input text using a regular expression pattern.
  • The regular expression pattern should capture the text after “Enter Project Administrator:” and before the next occurrence of “Enter Project” or the end of the text.
  1. Process Matches:
  • Iterate through the matches obtained from the Matches activity.
  • Add each match to the Data Table as a new row.

Please let me know if my suggestion resolves your issue.

Thank you :slight_smile:
Happy Automation!!
Hrishikesh Kothale.

Thank you for your answer!
I was able to extract this data using Find Matching patterns activity.
But I’m totally lost on point 3. I don’t know what exactly I should do
How to make it so that in DT there is only a username in each row.

Hi @damian.g

=> Build Data Table
image
Output-> dt_Output

=> Assign activity:

Input = "Select the right Service: Project CreationEnter Project Administrator: User1Enter Project Administrator: User2Enter Project Administrator: User3Enter Project Category: None"

=> Use Find Matching Patterns activity and give the below values as per properties name

Pattern = "(?<=Project Administrator:\s+)[A-Za-z]+[0-9]+"

Text to Search in = Input

Result = Matches

=> Use For Each loop to iterate through matches Variable and inside the loop use Add Data Row acitivity and give like below:

For Each currentMatch in Matches
    Add Data Row
        ArrayRow =  {currentMatch}
        DataTable = dt_Output
End For Each

=> Use Write Range Workbook to write the dt_Output to excel
image


Sequence.xaml (10.7 KB)

Regards

Hi @vrdabberu,
Thank you very much. One question- What if different values are substituted under “User1”, “User2”, etc. - e-mail or account name, e.g. damian.test@gmail.com or DamianTEST.
Instead of the word “User1” there can be any possible string of characters and special characters.
Best Regards,
Damian

Hey @damian.g

You can use this regex: (?<=Project Administrator: )(.*?)(?=Enter|$)
It will fetch all the mentioned possibilities from your string as you can see in below screenshot!

If it resolves your query, just mark this post as solution it will help others to get correct solution.

And special thanks to @jawagarraja123

Thanks & Regards,
Ajay Mishra

1 Like

Works perfectly!
Thanks @vrdabberu and @Ajay_Mishra

1 Like

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