Kamath
Kamath

Reputation: 4664

Regex to match comma + newline

I'm looking for a regular expression to check occurrences of , and the newline character together. I would prefer it with egrep.

Example:

strstr("Hello World","Hello");

should not match, and

strstr("Hello World",
       "Hello");

should return a match.

I tried both egrep ',\n', and egrep ',$', but was unsuccessful.

Upvotes: 1

Views: 8317

Answers (2)

John Watts
John Watts

Reputation: 8875

My guess is there is either whitespace after the comma or you have the wrong type of line endings in this file. I would start with this to see if it hits. Then scale back:

',[ \t\l\f]*[\n\r]*'

Upvotes: 1

buckley
buckley

Reputation: 14071

Have you tried

,\r\n

Depending on your platform this is different

\r    Mac up to OS 9 
\n   UNIX/Linux, Starting from Mac OS 10 (OS X)
\r\n DOS

The regex

,$

Should also work, and is more universal, but remember to set the option so that $ matches at line breaks and not only the end of your entire string.

Upvotes: 2

Related Questions