A cloud-based identity and access management service for securing user authentication and resource access
Hello @Sridevi Machavarapu
As per my requirement, i have used the regex in a customized way, which solved the issue.
Hope this helps others too.
I have attached the code snippet below.
string pattern = @"(\r\n){2,}";
string output = Regex.Replace(content, pattern, match =>
{
int count = match.Length / 2;
int startIndex = match.Index;
int endIndex = match.Index + match.Length;
bool precededBySlashParen = startIndex >= 2 && content.Substring(startIndex - 2, 2) == "/)";
bool followedByKeyword = false;
foreach (Match isMatch in Regex.Matches(content, $@"(?<=\r\n)({keywordsPattern})"))
{
if (isMatch.Index == endIndex)
{
followedByKeyword = true;
break;
}
else if (isMatch.Index > endIndex)
{
var intermediate = content.Substring(endIndex, isMatch.Index - endIndex);
if (string.IsNullOrWhiteSpace(intermediate))
{
followedByKeyword = true;
break;
}
}
}
string result = "";
for (int i = 1; i <= count; i++)
{
if (precededBySlashParen && i == 1)
{
result += "\r\n";
}
else if (followedByKeyword && i == count)
{
result += "\r\n";
}
else
{
result += "\r\n ";
}
}
return result;
});