How can I get text a before a certain string of word?

Hello guys, I need some help.
How can I get text a before a certain string of word?
For example,

“BOP AUTO STATUS” and the answer is “BOP”
“BCRC PER WRITE AUTO STATUS 06042020” and the is answer “BCRC PER WRITE”

I already found the answer in this topic How can I get text after certain string of word...can anyone help in this regard - #3 by saneeth_kandukuri

But Idk how to modify the IndexOf. Also, I can’t reply to the related topic bc it was closed.

2 Likes

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(strData,".*(?=\s*AUTO STATUS)").Value

Regards,

4 Likes

.*(?=AUTO STATUS)

you can try this!
@Shaira_Janine_Torio

3 Likes

It’s working! Thank you so much

1 Like

This is also working! Thank you so much!

1 Like

Save this link for next time regex101: build, test, and debug regex :slight_smile:

Regex101.com is a great place to test out and understand Regex solutions especially when changing to suit your needs :wink:

1 Like

Noted on this. Thanks!

1 Like

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