Share via

Implement lambda function for REGEXREPLACE

Anonymous
2024-05-22T18:55:12+00:00

This would be cool if REGEXREPLACE would have LAMBDA function for further replacement logic. The MatchEvaluator delegate in .NET does this job. The pseudo function would like this:

=REGEXREPLACE("This is regex 123 and 456", "[1-3]+", LAMBDA(match, LET(m, --match, IF(m=123, m*2, m*3)))) So, when regex finds "123" string, it passes it to lambda, which processes this matched value the way it's required. In this case, if match is equal to 123, then it's double, otherwise it's tripled.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-05-23T03:42:58+00:00

    In .NET there's overload to Regex.Replace method in which it accepts method with passed Match object into it (MatchEvaluator delegate). You can do any manipulations with a match. Returned string will replace found string. Is it clear now? In Excel terms, it would be LAMBDA function which accepts one argument.

    0 comments No comments
  2. Anonymous
    2024-05-23T02:56:52+00:00

    I am not sure if I understand you.

    This is a kind of callback.

    so pass REGEXREXTRACT("This is regex 123 and 456","[1-3]+",1) as array to reduce may be an option.

    0 comments No comments