Use regex to extarct Digital numebrs

Hi ,

i hope can someone support in this Task i want to use REgex to extract just one string from text
example form below i want to find just the First digital numbers after BE2 in this case will be (402934832)

Thanks a lot
example
Description Tax Number Establishment Status Establishment Status Text Edit Detail BE0 Belgium: VAT Registration Number BE0402934832 Edit Detail BE2 Belgium: VAT Reg. No. w/o country code 402934832 Edit Detail IN2 India: Permanent Account Number (PAN)12454 Industries Business Partner Block & Deletion",
“level”: “Information”,

1 Like

@Abdalla

Will this always be a nine digit number, if yes then you can use
(?<=[ |_])(\d{9})

1 Like

Hi yes its always a nine digit number but the issue i want to take just the correct nine digit number
this why i want to make sure its the 9 digit number comeing after the word (BE2 Belgium)

example
Description Tax Number Establishment Status Establishment Status Text Edit Detail BE0 Belgium: VAT Registration Number BE0402934832 Edit Detail BE2 Belgium: VAT Reg. No. w/o country code 402934832 Edit Detail IN2 India: Permanent Account Number (PAN)12454 Industries Business Partner Block & Deletion", IN2 India 202934852.
“level”: “Information”,

You can very well use (?<=[ |_])(\d{9})

Does the number always come in between country code and Edit Detail ?

like below …

country code 402934832 Edit Detail

yes always

for this case the country code is BE2 Belgium

yes and for this case the country code is BE2 Belgium

one more thing i donot want regex looking for this text": VAT Reg. No. w/o country code" between BE2 Belgium and Edit Detail becasue its not unique :slight_smile:

Use below,

where str = System.Text.RegularExpressions.Regex.Matches(str,“(?<=BE2\s)*\d+(?=\sEdit Detail)”)(1).Value

image

Thanks a lot for support its really great just small thing can you please adjust the code to make it extract just 9 digital numbers becasue now it extract every digital numbers also if they more 9 digital numbers

1 Like

Can you please try my above solution?

@Abdalla

The following should do:

pattern = "BE2 Belgium[\s\S]+?\b(?<code>\d{9})\b"
code = System.Text.RegularExpressions.Regex.Match(myText, pattern).Groups("code").Value
1 Like

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