REGEX Help needed to extract Invoice Number

Hello Guys, I need your help:
Input ------------------------------Output
Invoice no. 00067250------------------67250
LX220727233ANI17
01993872209006CB
00067183-----------------------------67183
INV 65739J41840Originalbetr.--------65739

Invoice Number starts with 6 or 7 and is 5 Numbers. Problem is that I dont want to be extracted anything in the records with input like: LX220727233ANI17 or 01993872209006CB
Sometimes Invoice number starts with 000 sometimes not, I don’t need the 000 part.

Can you please build a REGEX to give the output outlined above?

Thank you so much

Hi @hurmet.noka ,
“Invoice Number starts with 6 or 7 and is 6 Numbers”
-however your o/p is 5 digits starting with 6 or 7 +4 characters

below regrex will find invoice numbers matching 4 till 5 characters starting from 6 or 7
([6|7][\d]{4,5})
pfb the pattern and test data using regex101
Regex101 pattern
Regards

Hello @hurmet.noka

Is this the static format for all the files? Can you share 2 real files here or a screenshot of both.

Thanks

Hey!

Try this:

System.Text.RegularExpressions.Regex.Matches(StrInputVariable,"[6]\d+").ToString

Reference:

Regards,
NaNi

1 Like

Hello @hurmet.noka How about this expression

System.Text.RegularExpressions.regex.Matches(Input,"(?<=Invoice\s+no.*)[6|7]\d{4}|(?<=INV.*)[6|7]\d{4}|(?<=000)[6|7]\d{4}")

Output

output

Below workflow for ref

Example.zip (3.2 KB)

What if it can start also with 7,
In this case i dont want to extract anything from this:
LX220727233ANI17
01993872209006CB
Thank you

In this case i dont want to extract anything from this:
LX220727233ANI17
01993872209006CB
Thank you

Your example extracts it.

Very Specific, I have different scenarios where there is no Inv or invoice but just a long text like this:
01993872209006CB
On this case i dont want to extract the bold part

give a try at:
grafik

refering to the groups
grafik
grafik

\b(0*?)((6|7)\d{4})
1 Like

You are fantastic!

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