To extract substring with Regex

Hi team,

I want to extract only the values inside the () for the below records in a datatable -

Spend_Category
Social (SZ01428)
Remit (CC01438)
Local (MCZ134438)
Vibrant (LC0134248)

Currently I am using a regex expression -

System.Text.RegularExpressions.Regex.Match(FCR_DT1(0)(“Spend_Category”).Tostring,“[0-9A-Z]+”).Value

But I am not able to fetch the correct values.
Can you please here?

Regards,
G

grafik
(?<=\().*?(?=\))

1 Like

Str=Regex.Match(Str_variable,“((.*?))”).Group(1).Value

Hey @gokul1904,

As suggested by @ppr you should use the Lookbehind and LookAhead method to get the desired result.
For more info go through Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions

Thanks,
Sanjit

Thanks a lot @ppr

image

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