Joey Gfd
Joey Gfd

Reputation: 509

How to find a carriage return without a line feed after it with regex pattern?

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?

Upvotes: 9

Views: 6188

Answers (2)

Ryan Gross
Ryan Gross

Reputation: 6515

This should do the trick:

 Regex.Match("\rtext\r\ntext.", "\r[^\n]", RegexOptions.Multiline);

Upvotes: 1

Howard
Howard

Reputation: 39207

What about the following regex with a negative lookahead:

\r(?!\n)

Upvotes: 11

Related Questions