I need to get the last number in each line.Text is extracted from PDf
Name batch order number amount page
Hiyu-4566 a3456 1 1 1,6789 1
Hiyu-5664 a3456 1 1 1,6789 7
Hiyu-5262 a3456 1 1 1,6789 8
Hiyu-6362 a3456 1 1 1,6789 15
Hiyu-6373 a3456 1 1 1,6789 23your tran started
So now from the above will be in string fromat I need to take the page number 1,7,8,15 until your trans started…This all will be in text format
ppr
(Peter)
May 2, 2023, 9:24am
2
Regex can help:
\b\d+(?=$|your tran started|\z)
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…
How to use regix in UiPath
ppr
(Peter)
May 2, 2023, 9:29am
4
we added the CheatSheet for this
e.g. Single Match
strValue = System.Text.RegularExpressions.Regex.Match(YourStringVar, YourPatternString).Value
Or
https://docs.uipath.com/activities/other/latest/user-guide/matches
Gokul001
(Gokul Balaji)
May 2, 2023, 9:31am
5
Hi @Demo_User
How about this Regular Expression
System.Text.RegularExpressions.Regex.Match(YourString,"\b\d+$|\d+(?=your tran started)").Tostring
Regards
Gokul
1 Like
Hello @Demo_User ,
Try this
System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\s)\d+$|(?<=\s)\d+(?=your tran)").Tostring.Trim
1 Like
When I use this am getting only the last digit …I want other page number as well
I want 1,7,8,15,23 as output not only 23
Try this
string.join(",",System.Text.RegularExpressions.Regex.Matches(YourString,"(?<=\s)\d+$|(?<=\s)\d+(?=your tran)"))
ppr
(Peter)
May 2, 2023, 9:51am
10
Demo_User:
as output not only 23
ppr:
e.g. Single Match
for all matches, we would use Regex.Matches method and then grabbing all values
by looping over the return result
or
using a LINQ for grabbing all values
Still returns single value
Try this
string.join(",",System.Text.RegularExpressions.Regex.Matches(YourString,"(?<=\s)\d+$|(?<=\s)\d+(?=\n|your tran)"))
Hi @Demo_User ,
Try the following expression in UiPath assign activity with a variable of MatchCollection type.
System.Text.RegularExpressions.Regex.Matches(YoutText,“\d+(?=\n|your tran started)”)
Thanks,
Dibyaprakash
Demo_User
(Demo User)
May 2, 2023, 10:16am
15
Could please keep the string in text file and pass it as string then test it…It is not working for me
Demo_User
(Demo User)
May 2, 2023, 10:20am
16
For me am getting the output 23, below i have document page number 1 of 14
Am getting 23,14 as output not the pervious values
Demo_User
(Demo User)
May 2, 2023, 10:28am
17
About attached is the input file
Am getting 23,14 as output
Demo_User
(Demo User)
May 2, 2023, 10:30am
18
Above is the input I have passed
Getting output 23,14
I need 8,15,23 as output
@Demo_User , If possible share the test document here,
Demo_User
(Demo User)
May 2, 2023, 11:18am
20
Sorry its inside the another machine I cant able to share it
@Demo_User
Try This
string.join(",",System.Text.RegularExpressions.Regex.Matches(YourString,"\b\d+(?=Your trans|\s\n)"))