Regex to replace Day of week values ​​with numeric numbers

I have below the line

q10MTWTHFSSUMT88797sdfsdfsdfws

where MTWTHFSSU are days of the week.

I need the following output

OUTPUT should be : q10j1234567MT88797sdfsdfsdfws

I tried q(\d+)([M]|[T]|[W]|[TH]|[F]|[S]|[SU]){1} but it didn't work.

+1
source share
1 answer

This is a problem that you probably shouldn't solve with regular expressions.

Use a regular expression to extract an array of letters of the day of the week. You can simply use any other method to simply get the part of the string you want to make your replacements on.

Then just use a loop to iterate over each of them, replacing it with your dictionary / map value.

In addition, C # (for example, almost any modern language) has a rich string library, with which you can replace substrings (in your case, the letters of the day) with other strings (in your case, "1", etc.), t need to run a cycle.

+1
source

All Articles