Extracting two characters after a word


#1

Hello friends,
I need to extract the two characters (Sì or No) positioned after the words: “Presenza Vincolo Polizza” .


When I try to use the Screen Scraping tull with FUll Text I get:
Presenza Vincolo PolizzaNo

How it is possible , maybe with regex, to extract the words next to it?
Thank you so much,
Camilla :slight_smile:


#2

Apologize if i seem to have misunderstood the requirement. I believe you want to extract the data displayed after the text ‘Presenza Vincolo Polizza’ which could be No or Si. Did you tried to use Substring to get that value.

I believe you can implement it something like this using ‘Assign’ activity,
stringArray = strFullTextString.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)
valueNoSi = strArray(0).Substring(23,2)

Let me know if that’s what you needed.

Thanks,
Rammohan B.


#3

Thank you so much @Rammohan91.
I have to extract the data which can be Si o No, which is attached to the words “Presenza Vincolo Polizza”.
I’ll try your solution as soon as possible.
Thank you so much,
Camilla :blush::blush:


#4

Hi,

Regex is definitely the way to go here mainly because this would warn you when something goes unexpected by default (meaning that it will only expect Si/No).

First you need to build a pattern, in our case "Presenza Vincolo Polizza (Si|No)"

  • Text will simply match itself, including the space (Presenza Vincolo Polizza )
  • Parentheses will declare a group within the pattern.
  • Pipe ("|") is the ‘Or’ operator in Regex.

Using the “Matches” activity in UiPath will accept the pattern above, an input string (the raw text) and will return you an Enumerable of System.Text.RegularExpressions.Matches.

It is advised to check if you have only one match before extracting the result, A simple if will do.

Next step is to access the “Groups” property of the match, which will contain only the part you are interested in (Si/No).

It can be done bellow, We will capture index 1 as the index 0 will represent all the initial pattern matched.

Assign match = regexMatches(0)
Assign strSiNo = match.Groups(1).ToString`

You can find a workflow example here

RegexSiNo.zip (2.5 KB)

Cheers


#5

Thank you so much @Florent_Salendres.
Your solution solved my problem.
Have a good day and thank you again for your precious help.
Camilla. :slight_smile:


#6

Hello @Florent_Salendres.
I need to extract the two characters (Sì coassicurazione or No coassicurazione) positioned after the words: “Tipo Coassicurazione:”
*


With the Scraper tool I get the following text:

How it is possible , maybe with regex, to extract the words next to it?
Thank you so much,
Camilla :slight_smile::blush::blush:


#7

Did you try using the similar format of regex as mentioned above for extracting previous values:

May be something like this: Tipo Coassicurazione(Sì coassicurazione|No coassicurazione)

Thanks,
Rammohan B.


#8

Correct, if you would like to extract the adjacent word to SiNo.
If you want to only extract the Si No value, the previous approach should word as well by just change the begining of the pattern “Tipo Coassicurazione (Si|No)”

Cheers