Need Regex for below File name

Hi All,

I need regex function for below file name i received file name with 3 different type there i mention the how i need the output.
*
Input : 913202211932.BGPLPS1549281825_Final_EWS
output : BGPLPS1549281825

Input : BGPLPS1546274078MCLite
OutPut : BGPLPS1546274078

input : 522022103259.BGE_IC_Worksheet_Retrofit_Lighting__Site_H0533
Output :522022103259
*

Thanks,
Karthik

Hi @Karthik_Murugesan

1 Like

@Karthik_Murugesan

Welcome to the community

  1. (?<=\.)[A-Za-z0-9]*
  2. [A-Z]*[0-9]*
  3. \d*

Usage System.Text.RegularExpressions.Regex.Match(str,"Regexpattern").Value

Hope this helps

Cheers

1 Like

–>[A-Z]+(\d{10})|\d{12}(?=.BGE)
image
If you need regex for all three at once

–>if needed seperately
for first 2 pattern->follow this regex [A-Z]+(\d{10})
for other use \d{12}

2 Likes

Hi @Karthik_Murugesan

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!!

1 Like