c# regex replace string within a specified string with spaces

Use the regex pattern to match ....
In .*: By default, the dot, ., matches any character except the newline character (\n) . The * means that it will match the preceding, ., 0 or more times. And, the ? after the * means that the * is lazy. This means that the dot will match as few characters as needed to make the match, i.e. lazy. This means that as soon as it comes to the first after the (without crossing newlines) it will match the string from the beginning to the end.

This string is then replaced by literal , to get the desired output.

REGEX PATTERN:

.*?

REPLACEMENT STRING:


INPUT STRING:

This is a sample string another string.string. Another string.

OUTPUT STRING:

This is a sample string . Another string.

Regex Demo: regex101.com/r/FA5f76/1

Read more here: Source link