My regex isn't working but works in regex builder and regex101

My regex is working in regex builder and regex101 but it’s not returning any values in my sequence. I am trying to get the account number.

(?<=Account Number:\n\n\n\n\t)\d+

test_text.txt (205 Bytes)

Hi @botdev75

Welcome to the UiPath Community Forum! :partying_face: You are in the right place.

To answer your question… the site .NET Regex Tester - Regex Storm is 100% compatible with UiPath (as far as I know :sweat_smile: ). IS NOT 100% compatible with UiPath but is fine to use for simple patterns. I find the differences are around the use of “Negative/Positive Look Behind/Ahead” type anchor patterns. In summary, Regex101 is good for simple patterns and learning Regex BUT for more difficult patterns use Regex Storm. I have created a Regex MegaPost where I have covered this briefly. @Yoichi is a forums expert on Regex (and pretty much everything).

Can you please provide:

  • sample (txt file attached - great)
  • Expected output
  • information on the pattern within the text

In the meantime,

I might have a pattern that will work based upon the text file. You can preview it here

This is the pattern:
(?<=Account Number:[\s]+)\d+
It will match any length of digits and any number of new lines, tabs or spaces.



it’s linebreak matter. regex101 and regex builder handles linebreak as LF (\n). Howevere, linebreak of Windows text file is CRLF (\r\n).
So the following pattern will work in both.

(?<=Account Number:\r?\n\r?\n\r?\n\r?\n\t)\d+

Note: if number of linebreaks might be increased or decreased, @Steven_McKeering 's pattern is better.


1 Like

Thanks for your responses. Apologies in advance as I am only a beginner!

I tried both patterns and they both work (as my original regex) but it’s still throwing an error. I am getting a feeling that it might not be the regex but something else? Anyway here is a screenshot of the error and the sequence. I am expecting the account number to be written out.


This error message shows there is no match in ienMatches. Can you review your string and pattern? If possible, can you share your string (item.Body)?


Thank you for the response Yoichi. I reviewed the string and the different pattern variations you provided and it all works in regex101 regex builder and regexstorm. The pattern correctly identifies the account number. But when I run the sequence I get the error which as you explained means no matches were found.

Attached is the item.Body.

string.txt (1.8 KB)

give a try on following:

and refer to group

Regex.Match(YourString,“(?<=Account Number)(?:(.|\n)+?)(\d+)”).Groups(2).toString

Tested on immediate panel

1 Like

It worked! There was a “bad” email that did not fit the pattern and for some reason it was causing the write line to fail. Once I removed the bad email, the pattern worked and extracted the account numbers from the other emails as expected. Much thanks for helping me!

Question, is there a better pattern that will identify the account number even if the Body text does not conform? OR is there a configuration that will “skip” bad emails and just move on to the next?

Attached is the Body text of the bad email I removed:

bademail.txt (3.1 KB)

Also working with bad email text:

Thanks Peter, that pattern works with the bad email!

perfect, just do your final testing. Once it working mark the solving post as solution or let us know your open questions. Other will benefit from it. Thanks

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