I am new to Uipath. I would like to extract the text next to the word “Name” in a text file. The word “Name” can appear anywhere in the text file, so I tried Anchor Base, but it doesn’t work.
Can someone help troubleshoot? I can’t attach my file as I am new to the Forum. I noted that Anchor Base works well in website, but can’t seem to work in .txt. Do I need to use another method?
Is there some resource that explains all the attributes in the selector?
How about using “Find element” → “Set Clipping Region” → “Get OCR Text”? I find the explanation support on Uipath website to be somewhat lacking. The explanation lacks clarity
At the end of the post I’ve attached one example for your better understanding use it if you need it.
As you said before,
Anonymous2:
The word “Name” can appear anywhere in the text file
So setting clipping region would not be a suitable option here.
We use Regex to search pattern.
I’ll suggest you to follow the steps below.
Firstly drag Read Text File activity at the starting of the sequence.
Select txt filename ( “Details.txt” ) from which you want to get the name.
Create String variable called Text1 and pass it to the output parameter of the activity.
Create one Name variable of variable type —> String & Take Assign activity like given below.
Name = System.Text.RegularExpressions.Regex.Match(Text1,"(?<=Name).+").Value
Take MessageBox with var. Name
Here’s one Example (If you need it) —>RegexEx.zip (13.2 KB)
This is LookAhead regex pattern (?<=Name - ) —> it’ll get text next to Name - till .+ end of the line. ( . —> any char & + —> one or more, .+ together it becomes —> any char one or more times.)
When it comes to tabular data we don’t use regex there, we have other method Or logic in DataTable type.
If you want to know anything more about regex LookAhead, Lookbehind, LookAround in depth then click here.
If my .txt file has data arranged in a rectangular tabular form, but without all the lines of a proper table what method should I use to extract the data?
I am able to extract the Customer_ID for Chr_D with
“(?<=Chr_D.{8}).+”
But I have a more difficult issue with another form. I want to extract the line below “COMBINED TEST FOR THE PRESENCE OF CLIMATE CHANGE”. How can I use regex to do so? Thanks!
COMBINED TEST FOR THE PRESENCE OF CLIMATE CHANGE
IDENTIFIABLE CLIMATE CHANGE PRESENT
(?<=Chr_D ).+ —> will extract text 100 12 345 but you want customer ID, for that we’ve used split method with " " one space & it’ll take last value. i.e —> 345
For your 2nd issue, take assign as given below
Nextline = System.Text.RegularExpressions.Regex.Match(Text1,"(?<=COMBINED TEST FOR THE PRESENCE OF CLIMATE CHANGE)(\n).+").Value