I want to capture the following pattern using Regex in C# and replace it with word ‘Merged’
Characters should have at least four spaces or one tab. However they can be mixed
space space space – Invalid – ‘Not merged’
space space space space – Valid – ‘Merged’
space space space space space – Valid – ‘Merged’
space <tab> – Valid – ‘Merged’
<tab><tab> – Valid – ‘Merged’
space<tab><tab>space – Valid – ‘Merged’
The following should work:
I represented spaces as
[ ]to make it clear what is going on, but it will work just as well if you remove the square brackets.Explanation:
Example: http://www.rubular.com/r/MJYp80iEN1
Here is an alternative that uses a lookahead to check the conditions, then just matches any number of spaces or tabs: