How to write regex in CSharp for below paths

Robotics Automation\P-PROD\Treaghgsury\Cogre\Ignput\DaiglyCollateralggJV\03 27 2023.xlsx
Robotics Automation\Dev\Treasghury\Core\Input\DailyCollatgeralJV\03 27 2023.xlsx
Robotics Automation\PROD\Tregasgghury\Coreg\Input\DaiglyCollgateralJV\03 27 2023g.xlsxa

Required

P-PROD
Dev
PROD

Hi @Manju_Reddy_Kanughula

You can use the following regex pattern:

(?<=Robotics Automation\).*?(?=\)

Output:

image

Hope this helps,
Best Regards.

1 Like

HI @Manju_Reddy_Kanughula

You can try with Split expression

Split("Robotics Automation\P-PROD\Treaghgsury\Cogre\Ignput\DaiglyCollateralggJV\03 27 2023.xlsx","\")(1)

image

Regards
Gokul

1 Like

Assumptions:
From the multiple samples, only 1 sample will be used for the Regex.
As the question was about C# we would and we assume the single line, so we are using Regex.Match:

strText value like:
Robotics Automation\P-PROD\Treaghgsury\Cogre\Ignput\DaiglyCollateralggJV\03 27 2023.xlsx
strPattern as mentioned by Arjun
(?<=Robotics Automation\\).*?(?=\\)

kinldy note: we escaped the \ with \\

strValue = System.Text.RegularExpressions.Regex.Match(strText,strPattern).Value;

1 Like