Get a word after some specific word from string

Hi everyone,
How do I get a word from a huge text file?
"МЭДЭГДЭЛ ХҮРГҮҮЛЭХ ТУХАЙ
ЭНХ-УНДРАХ ОВОГТОЙ НАНДИН-ЭРДЭНЭ 89082920 НЬ БАНКТАЙ 2022 ОНЫ "
Can I get “ЭНХ-УНДРАХ” using “ТУХАЙ” and “НАНДИН-ЭРДЭНЭ” using “ОВОГТОЙ”?

I used to get these words using “System.Text.RegularExpressions.Regex.Replace(ovognerstr1,”[1]\s+(\w+)\W+овогтой\W+(\w+)[\s\S]$“,”$2 $1").ToUpper" but its not working for some reason
Regards,
Temuulen


  1. \s\S ↩︎

Hi @Temuulen_Buyangerel
Regex Expression:

[A-Z]+\-+[A-Z]+
input="NOTICE DELIVERY NANDIN-ERDENE 89082920 WITH THE SURNAME
ENH-UNDRAH IS WITH A BANK IN 2022 "

output=System.Text.RegularExpressions.Regex.Matches(input,"[A-Z]+\-+[A-Z]+")

Datatype of input is System.String and output is IEnumerable(System.Text.RegularExpressions.Match)

Refer the below image for better understanding!!



image

Hope it helps!!

1 Like

Hi @Temuulen_Buyangerel ,
You can try
strResult = System.Text.RegularExpressions.Regex.Match(YourEntireData,“(?<=[A-Z]{7}\s[A-Z]{2}:\s)[0-9]{6}”, RegexOptions.IgnoreCase).Value

or
strResult = System.Text.RegularExpressions.Regex.Match(YourEntireData,“(?<=Invoice\sNo:\s)[0-9]{6}” , RegexOptions.IgnoreCase).Value
Regards,
LNV

1 Like

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=ТУХАЙ\s+)[-\w]+").Value

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=ОВОГТОЙ\s+)[-\w]+").Value

Sample20230810-4L.zip (2.4 KB)

Regards,

1 Like

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