Regex matching extra letter to the given word

Hi All,

My sheet names in excel are 2021-SMC , 2022-SSC , SMC - 2020 and earlier and SSC - 2021 and earlier

so year is the dynamic one here , so to read the sheet using get workbook sheet activities

I used regex :
system.text.regularexpressions.regex.ismatch(sheet,"\d - SMC") or system.text.regularexpressions.regex.ismatch(sheet,"\d - SSC") or system.text.regularexpressions.regex.ismatch(sheet,“SMC - \d{4} and earlier”) or system.text.regularexpressions.regex.ismatch(sheet,“SSC- \d{4} and earlier”)

But it is also matching sheet names like this 2022 - SMC_1 or 2021 - SSC_copy etc

Help me solve this problem

Thanks in advance

HI @kavya.s16

Try out this regex

It will match all the four patterns you want to match
((\d±SMC)|(\d±SSC)|(SMC - \d+ and earlier)|(SSC - \d+ and earlier))


update us whether you got your desired answer or not

Thanks,
Robin

I dont want it to match 2021 - SMC_copy or 2021 - SMC_1 but just match 2021 - SMC

Hi @kavya.s16

it will not match & try again with my regex
Update us whether you got your desired solution or not

Thanks,
Robin

HI @kavya.s16

You can also try this alternative expression
((\d{4}-\D{3})|(\D{3} - \d{4} and earlier))

Regards
Sudharsan

1 Like