I need to find a carriage return (\r) that doesn't have a line feed (\n) directly after it how would I do this with a regex pattern?
You can use special character sequences to put non-printable characters in your regular expression. Use \t to match a tab character (ASCII 0x09), \r for carriage return (0x0D) and \n for line feed (0x0A).
\n. Matches a newline character. \r. Matches a carriage return character.
If you want to indicate a line break when you construct your RegEx, use the sequence “\r\n”. Whether or not you will have line breaks in your expression depends on what you are trying to match. Line breaks can be useful “anchors” that define where some pattern occurs in relation to the beginning or end of a line.
The dot matches all except newlines (\r\n). So use \s\S, which will match ALL characters.
What about the following regex with a negative lookahead:
\r(?!\n)
This should do the trick:
Regex.Match("\rtext\r\ntext.", "\r[^\n]", RegexOptions.Multiline);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With