Regex activity, I can't find any matches

Hello, I’m starting with regex and I don’t understand it yet, I have two cases that I can’t find, the first is this, I need to locate the number that is just above Client, it can be a number or a text

city-
12345678X
Client
Number

in the second case, I need to put the content between Ser and Desc in a variable, it always has that format, thank you very much for the help

Ser
5814
01/11/2022
099
Desc

What do you need to extract from this string? @Kuro

HI @Kuro

Try with this Regex

YourString = “city-
12345678X
Client
Number”

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=city\W\n)\S.*").Tostring

image

Regards
Gokul

Thanks for the answer, but “city” is changing, it is always different, Client is fixed

@Kuro

System.Text.RegularExpressions.Regex.Match(YourString,"\S.*(?=\nClient)").Tostring

image

works fine!!

I had another query, can you help me?

Hi @Kuro

you can use this

str is the string then str.Split(“Client”,2,StringSplitOptions.None)(0).Trim.Split(Environment.Newline(),2,StringSplitOptions.None)(1).trim

for replacing if you want to retain previous centent then do str2.Replace(“Desc”,Envitonment.Newline() + str + Envitonment.Newline() + Desc)

cheers

Great @Kuro

For that Can you please create the another topic. Kindly close this topic by mark as solved. It will help for other user too.

For this @Kuro

Simple use like this : "Ser"+vbNewLine+YourString+vbNewLine+"Desc"

Regards
Gokul

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