Hi Guys,
I tried to create a pattern using regex in matches activity in uipath but its not recognising
Starts with and Ends with
Why is this?
Can anyone share a workflow where youve used ^ and $ in your expression please
@Dheeraj_S
may we ask you for your sample text, the pattern and a small description of expected output? Thanks
sample scenario1:
Description
7731642
2717000 10
sample scenario2:
Description
7731642
2717000 10 industry
sample scenario3:
Description
7731642
2717000
Pattern:
\d{7}\n(^\d{7}\s+\d{2}$|^\d{7}\s+\d{2}\s+[A-Za-z]+$|^\d{7}$)
Ineed to pick 2717000 in any of these 3 scenarios
Hello @Dheeraj_S ,
Other pattern
pattern = "(?<=Description\s\d{7}\s)\d{7}"
(link to result on regex101 below)
Multline Match
Did you use Multiline RegexOption?
import System.Text.RegularExpressions
pattern = "Description\s+^\d+\s+^(?<result>\d+)"
match = Regex.Match(myText, pattern, RegexOption.Multiline)
Hello @msan,
The word description is not constant, it keeps changing.
The only constant things are the two 7 digit numbers.
Example:
hfgwhfgigfjsdjgfjg 1000 djhg
7731642
2717000 10
@Dheeraj_S
give a try and refer to group 1
description 30733459 2000279367
7731642
2717000 10
For the above text i’m getting 3 matches with your pattern.
i should only get one
@Dheeraj_S
adopt with (?<=^\d{7})\s*(\d{7})
@ppr It works:)
What if the text changes in this way.How to change the pattern to adopt this change given below:
Scenario1:
description 30733459 2000279367
2717000 10
shfjhgfahfjhfvshfgahfggfhj
Scenario2:
description 30733459 2000279367
7731642
2717000 10
sahafujsghfhafghfja
Scenario3:
description 30733459 2000279367
7731642 10
2717000
jbhdaguahgajdgashg
In every case we need to pick 2717000.
Occasionally there will be a 7 digit reference number above this but not every time.
You should provide right away all variations you can think of in the samples We’re not only writting a regex here but mainly trying to find a pattern to then express as regex. In that process we tend to spot what doesn’t change and how the variations work.
May I assume you’re simply looking for the last seven digits number?
pattern = ".+(?<result>\b\d{7}\b).*?$"
match = Regex.Match(myText, pattern, RegexOption.Singleline)
result = match.Groups("result").ToString
@msan Read pdf with ocr is giving unexpected output so i was trying out various parameters so i couldnt give out all the variations at once.
Yes i’m looking for the last seven digit number which is sometimes preceeded by another 7 digit number as shown in the example.
Since the ocr is not getting all the relevant data out of the pdf i’m having trouble forming patterns.
Thanks for your response
Don’t worry, I’ve guessed it. But it as you will get more case, you’ll probably have to do this again.
And you’ll thanks me later: collect many samples first and you’ll have a better reading of the patterns. Then the regex is just an expression.
@msan
Will do. Thank you so much:)
Because you’re always looking for this 2717000 in each scenario why don’t you just look for that rather than having an overly complicated regex? Example below…the site I use to validate my regex patterns is regexr.com:
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.