Regex or better logic need to get particular data from string

Hi Friends,
I need to extract some project id from file name in below string.
for 1 file we received 3 different filenames as mentioned below,

input: 913202211932.BGPLPS1549281825_Final_EWS
output : BGPLPS1549281825

Input: BGPLPS1546274078MCLite
OutPut : BGPLPS1546274078

input : 522022103259.BGE_IC_Worksheet_Retrofit_Lighting__Site_H0533
Output :522022103259

Thanks,
Vicky

Same question

A suboptimal approach, but can work as interim solution


^\d+|B[A-Z\d]+\d

System.Text.RegularExpressions.Regex.Matches(strText, strPattern).Cast(of Match).Last().Value

Hi @Vicky_K

You can use the below regular expressions to extract the required output.

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=\d+\.)[A-Z]+[0-9]+|[A-Z]+[0-9]+(?=[A-Z]+)|[0-9]+(?=\.[A-Z]+\_))”)


The above Regular expressions will extract the required data if the name of the file is any of three.

Hope it helps!!