Need Regex for Below these String value

Hi team ,

My String value is “March 13,2024”
in these I need only these Output

“March 2024”

can you any one help me these issue

@Mada_Sai_Krishna

StrDate=DateTime.ParseExact("March 13,2024","MMMM dd,yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MMMM yyyy")

image

or

System.Text.RegularExpressions.Regex.Match("March 13,2024","[A-Za-z]+").Value+" "+System.Text.RegularExpressions.Regex.Match("March 13,2024","\d{4}").Value
1 Like

Hi @Mada_Sai_Krishna

For this no need to use regex you can simply use the DateTime manipulations, Check the below one,

- Input = "March 13,2024"
- Output = DateTime.ParseExact(Input.toString, "MMMM dd,yyyy", System.Globalization.CultureInfo.InvariantCulture).toString("MMMM yyyy")

Or you can use the below regular expressions,

- Assign -> Input = "March 13,2024"
- Assign -> Output = String.Join(" ",System.Text.RegularExpressions.Regex.Match(Input.toString,"[A-Za-z]+(?=\s+\d+\,)|\d{4}"))

Check the below workflow for better understanding,

Hope it helps!!

Hi @Mada_Sai_Krishna

[A-Z|a-z]+|\d{4}

Hope it helps!!

Hi @Mada_Sai_Krishna

Try this

Regards,

Hi @Mada_Sai_Krishna

Try this:

System.Text.RegularExpressions.Regex.Replace("March 13,2024", "\b\d{1,2},\b", "").Trim()

image

Hope it will helps you :slight_smile:
Cheers!!

1 Like