How to get codes from my string?

Hi everyone! I have two strings

  • string1: “Membership Depo 9959/ 2022 XLA MAGZS UPS”
  • string2: “Membership Alti Depo / 5251 Camlik Abz UPS”

I have to get 9959 and 5251 codes. How to get codes?

@ozgecatak,

Will it come always after “Depo /” and “Depo”?

@ozgecatak

First string 1

System.Text.Regularexpressions.Regex.Match(str1,"\d{4}(?= *\/)").Value

For string 2

System.Text.Regularexpressions.Regex.Match(str1,"(?<=\/ *)\d{4}").Value

Cheers

Yes it will come like it

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"\d+").Value

Regards,

Teşekkürler :slight_smile:

1 Like

Hi @ozgecatak

If the codes are always before and after / you can try below expression

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=Depo\s)\d+|(?<=Depo\s\/\s)\d+").Tostring

Regards
Sudharsan

use regex “/d” to get all digits from the string post that you can use substring function to get the desired digit u want

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