Extract string between two references

Hi all,

I have a string variable that has the following content: “Exmo.(a) Senhor(a)\r\nA23456789\r\nRua”. I want everything that is between “Senhor(a)” and “\r\nRua”. Any ideas?

Thank you,
Cátia

Refer this regex

If MyText is equal to “Exmo.(a) Senhor(a)\r\nA23456789\r\nRua”, set another variable to System.Text.RegularExpressions.Regex.Match(MyText, "(?<=Senhor\(a\)).*(?=\r\nRua)").Value.

1 Like

It isn’t displaying anything…

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(text,"(?<=Senhor\(a\))[\s\S]*?(?=\r\nRua)").Value

Regards,

Thanks! This solves it :slight_smile:

Now 2 more points that I want to had:

  1. The first delimiter is “Senhor(a)\r” (not only “Senhor(a)”);
  2. The second delimiter doesn’t have always the word “Rua”. What I know is that what I want is between “Senhor(a)\r” and the next time “\r” appears.

Any sugestion?

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(text,"(?<=Senhor\(a\)\r)[\s\S]*?(?=\r)").Value

Regards,

1 Like

Thank you so much!!

1 Like

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