shternik
shternik

Reputation: 67

Java: regexp to match \n with only one \

I need a regexp, that matches \n everywhere, except \\\\\n (n with multiple \) Every other variant is suitable. For example:

Sorry, if it's a dumb question, I tried googling, but with no success

Upvotes: 0

Views: 82

Answers (3)

hwnd
hwnd

Reputation: 70750

I believe you are looking for a Negative Lookbehind here.

(?<!\\)\\n

See Demo

Upvotes: 1

AlexR
AlexR

Reputation: 115398

You need negative lookahead. Try something like this: (?!\\)\n. Probably you have to duplicate the slashes, i.e. write something like (?!\\\\)\n

Upvotes: 1

mkubacki
mkubacki

Reputation: 585

Tried using "\\n" as a pattern?

For clarification the first \ is just for escaping special character

Upvotes: 1

Related Questions