Regex for get value

I have value as below.
xxx_Cost_USD_Normal_D20240722_I_Lot1 ----> I want output 202407
xyyu_Summary_USD_Special_D20241022_4545 —> I want output 202410
xxx_Sum_Money_CES_BBC12_May_2024L12 —> Output 202405
xxx_Sum_Money_CES_BBC4
April_2024_L4 —> Output 202404

Please guide me for solve it.

Thank you

Hi @fairymemay

You can use the this pattern for regex

2024\d{2}

Hope this helps :slight_smile:

@AJ_Ask if next year 2025 I must edit code?

Can use int 6 character for check it?

202[45]\d{2}

This will work for both 2024 & 2025

Hi @fairymemay

You can use the below Expression to get the required output.

- Assign -> InputString = "xxx_Sum_Money_CES_BBC12_May_2024L12"

- Assign -> OutputString = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(InputString.ToString, "(?<=)\d{6}|[A-Za-z]+_\d{4}").Value.ToString, {"yyyyMM","MMMM_yyyy"}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None).ToString("yyyyMM")

Check the below workflow for better understanding,

The above expression is work for all the values.

Hope it helps!!

1 Like

@mkankatala error as below.

How to solve it?

Thank you

Can you show me what the InputString variable has… @fairymemay

InputString variable has to be in String datatype.

In which activity you are passing this expression.

Okay I can solve it. @mkankatala

Can you recommend this case.
xxx_Cost_USD_Normal_D20240722_I_Lot1 ----> I want output 202407
xyyu_Summary_USD_Special_D20241022_4545 —> I want output 202410

Okay @fairymemay

I hope you find the solution for your query, If yes Mark my post Mark as Solution to close the loop.

Happy Automation!!

The above expression will work for both… @fairymemay

Same expression as I given in the above post,

See the below one,

- Assign -> InputString = "xxx_Cost_USD_Normal_D20240722_I_Lot1"

- Assign -> OutputString = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(InputString.ToString, "(?<=)\d{6}|[A-Za-z]+_\d{4}").Value.ToString, {"yyyyMM","MMMM_yyyy"}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None).ToString("yyyyMM")

Hope it helps!!

1 Like

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