R
R
Roman Koff2021-10-27 15:31:28
Regular Expressions
Roman Koff, 2021-10-27 15:31:28

How to remove duplicate occurrences at the end of a string using Regex in C#?

Very simple question, but I'm not strong in regular expressions.
There is a string s1 and you need to delete all occurrences of the substring s2 in it, if they are in a row from the end.
For example:

s1 = "qwertyuiop asdfghjkl zxcvbnm abc abc abc";
s2 = " abc";
// в результате должно пулучиться "qwertyuiop asdfghjkl zxcvbnm"


I have this function made by recursion, but I would like to have a more elegant solution on regular expressions.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question