Skip to content
Advertisement

Capture substring and send it to a function that modifies it and can replace it in this string

JavaScript

Incorrect output that I am getting, because if I incorrectly capture the substrings, the replacements will also be incorrect

JavaScript

Having well-defined limits, I don’t understand why this capture pattern try to capture beyond them?

And the output that I need is that:

JavaScript

Advertisement

Answer

There are several errors in your code, among which:

  1. You are printing the result of the one_day_or_another_day_relative_to_a_date_func function. Print the result of identify instead.
  2. In the identify function you are not returning the result text. Add return input_text at the end of it.
  3. Make the “o…” suffix optional.
  4. Use regex alternation instead of multiple patterns, otherwise you may get unexpected results.

Fixed code (I’ve also made it more compact):

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement