Regex: Find all 9 Digit Numbers after the word "Vertrag"

I have a problem. I need to find all the Contract numbers in a csv that results out of a Get Visible Text Activity. I wrote them into a csv file and got this result:

Column1;Von;Erhalten;Nachricht;Column2;Column3;Empfänger;Sonstiges
Name;Vorname;<Datum Betreff;;Name;;Vorname ID des Anhangs;
Benutzercode;Durchwahl;Uhrzeit Gelesen;;Code;;Durchwahl Kommentar des Anhangs;
Meier;Marcel;30.10.2019 A-Konto-Zahlung Vertrag 7732151;;Schnitzel Petra;;978404;
Meier;2112;14:36:12 26.11.2019;;Schnitzel;3103;A-Konto-Zahlung Vertrag 7732151;
STOPDAGEHT;Eveline;08.08.2019 A-Konto-Zahlung Vertrag 7652254;;Kurz Hartman;;978334;
STOPDAGEHT2104;;15:08:50 . .;;Kurz;;3105 A-Konto-Zahlung Vertrag 7652254;

I need to get the 7 Digit-Number after the word: Vertrag There is always a “;” behind it. Please help.

Greetings,

Simon

2 Likes

Hello welcome.

(?<=Vertrag\s).[0-9]+

it helps?

4 Likes

HI
if the above string is input for variable str_input
then
in MATCHES ACTIVITY with that str_input as input and expression as
(?<=Vertrag).[0-9]{7}+

this will give us

and if we need all numbers next to Vertrag with no digit count restriction then
as @KMota suggested that would work

Cheers @SSchmitz

3 Likes

Wow Guys!
Thats a great support! I love this commuity! Very fun to work with this.
Cheers!

2 Likes

Cheers @SSchmitz

Can somebody show me the syntay on how to use this in an assign activity?

My variable is test
System.Text.RegularExpressions.Regex.Match(test, (?<=Vertrag\s).[0-9]+).Value

2 Likes

You can use the Matches activity, and then for each match, do the actions, since all the matches will be stored in a collection variable.

Hope that helps :slight_smile:

Thanks for your help. But I don’t get it to work properly.
So I’m reading out the text. Then generating a DT and a CSV. Then I use the Matches Activity.
Then I use a Write Line to see what is in the collection. This only works when I use to String. But the Output is trash :confused:
" System.Linq.Enumerable+d__97`1[System.Text.RegularExpressions.Match] "

Thanks for helping Guys

@SSchmitz
the toString() will output the Datataype. It is recommended to:

  • set breakpoint and inspect variable content in the locals panel
  • iterate over the Enumerable “Collection” and output the looped item

Wird schon irgendwie klappen, ansonsten sind wir ja für dich da

2 Likes

Yah you are almost done
It would be like this
str_output = System.Text.RegularExpressions.Regex.Match(test.ToString, (?<=Vertrag\s).[0-9]+).ToString

Where str_output is a variable of type string
As you have mentioned Match activity it will give only one match

If we have used Matches which would give us many such matches then the assign activity would be like this
match_Values = System.Text.RegularExpressions.Regex.Matches(test, (?<=Vertrag\s).[0-9]+)

Where match_Values is a variable of type
System.Collections.Generic.Ienumerable(System.Text.RegularExpressions.Match)

Cheers @SSchmitz

1 Like

What that’s a lot of info and help! I will just input my Workflow here. Basically what I want it to do:
Extract the Visible text find the Contract Numbers and Write them all in a CSV File. Each in One Line. Any Ideas? :slight_smile:
Maybe the workflow helps.
Read_it.xaml (8.5 KB)Hobbit.txt (6.6 KB)

Hi @SSchmitz,

Please use the below syntsx -
System.Text.RegularExpressions.Regex.Matches(YourString,“(?<=Vertrag\s*)[0-9]{7}(?=;)”)

Hope you will find your solution.

Thanks & Regards,
Apurba

2 Likes

At what point or in which activity in my Workflow should I put this? Thx

@SSchmitz

You can use assign activity and create a variable with string and write the code in assign activity like above mentioned

System.Text.RegularExpressions.Regex.Matches(YourString,“(?<=Vertrag\s*)[0-9]{7}(?=;)”).value

You will get the matched value then you can use for your process.

Thanks,
Aman Sheik.

@SSchmitz

For your reference try this

Regex.zip (11.1 KB)

Hope this helps!!!

Thanks,
Aman Sheik.

1 Like

This is great aman! Thanks!

1 Like

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