Could you please provide a regular expression that I can use to replace all \r\n in a string, only when \r\n is not preceded by .?
Could you please provide a regular expression that I can use to replace all
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To match a character, you can place the character inside brackets such as
[.]. To not match it, you can start the character list with a caret such as[^.]. This will effectively match any character that is not a..For your specific case, you want to match
\r\nthat doesn’t have a.in front of it. Combined with the above, you can use:To replace it, you’ll want to “capture” the character that is not-a-period to keep it in the replacement. You can capture it by wrapping it in parentheses, such as
([^.]).Using
Regex.Replace(), it would be something like:The
$1is the character matched and is re-replaced back into the string, now stripped of the\r\n.