Regex for 2 different conditions

Can someone help me or give an idea for a regex that would work to this 2 different conditions.
A single lined regex that would get both output . Thanks for any help.

#First Condition - Data1

If joint return, spouse’s first name and middle initial

Last name

BOYER

Last name

output : BOYER

#Second Condition - Data2
Your first name and middle initial Paul A Last name Staffer Your social security number 184-80-8799
If joint return, spouse’s first name and middle initial Judith B Last name Staffer Spouse’s social security number 185-80-9544

Output : Staffer

Current regex : System.Text.RegularExpressions.Regex.Match(data,"(?<=Last name).*?(?=Your social security number)").Value

1 Like

regex_2_condition.xaml (4.4 KB)

Please check this…! @AhmedKutraphali

Updated Regex: System.Text.RegularExpressions.Regex.Match(strInput,“(?<=Last name)( \w+|\s\w+)”).Value.Trim

Thanks!

I mean something like this Sir

(?<=Last name).?(?=Your social security number)|(?<=Lastname)[\S\s](?=Lastname)

@kadiravan_kalidoss

Hi @AhmedKutraphali

Please try this

(?<=Last name\n)[\w\W]*(?=Last name\n)|(?<=Last name )[\w\W]+(?= Your social security number)

Thanks

1 Like

Please try this updated one,

(?<=Last name\n)[\w\W]*(?=\nLast name)|(?<=Last name )[\w\W]+(?= Your social security number)

image

image

Thanks

1 Like

Why is it working here
image

but when I tried
System.Text.RegularExpressions.Regex.Match(data,“(?<=Last name\n)[\w\W]*(?=\nLast name)|(?<=Last name )[\w\W]+(?= Your social security number)”).Value

the output is empty
image
image

@prasath_S it should not include other text Sir

can you please send the text…

@AhmedKutraphali - May we ask …please don’t mark as solution before completing your test …

Take your time and run through your test and once done then go ahead mark as solution

Have you dummied the SSN # posted here?

@AhmedKutraphali - Is this the output you are looking for?

image

Please try this and let us know.

NO @prasath17

@prasath_S have given men asnwer which is

System.Text.RegularExpressions.Regex.Match(data,“(?<=Last name\n)[^Last name]\w*(?=\nLast name)|(?<=Last name )[\w\W]+(?= Your social security number)”).Value

it works on regex101 but it does not work on uipath

@AhmedKutraphali -

Regex Strom Link

1 Like

@AhmedKutraphali - it is working correctly for the text given above

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