3

I have a string:

\r\ndsadasdsad\das\rdasdsacxz\ndasdsa\r\nadsadas\e

I want to make a regexp that will match all characters with '\' in front of them, but not "\r\n", so it would be '\.' without '\r\n'

georg
  • 211,518
  • 52
  • 313
  • 390
karlkar
  • 227
  • 1
  • 5
  • 12

4 Answers4

3
\\r(?!\\n)|(?<!\\r)\\n|\\[^rn]

Live demo

revo
  • 47,783
  • 14
  • 74
  • 117
0

This regex should match a single character that is preceded by a \, but is not part of the sequence \r\n:

(?:(?<!\\)|(?!r\\n))(?:(?<!\\r\\)|(?!n))(?<=\\).

You can find an explanation here.

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
-1

This will match all characters which are not "n" or "r" and which have a slash in front of them.

(?<=\\)[^rn]
mtanti
  • 794
  • 9
  • 25
  • 1
    So it will not match \r or \n separately - I want them to be matched if they not occur together. Only when there's '\r\n' I want them not to be matched. – karlkar Jan 07 '14 at 17:00
-1

Ok, this should do what you're asking.. :

As per your question this matches "ALL characters with '\' in front of them, but not '\r\n'"

Test String:

\r\ndsadasdsad\das\rdasdsacxz\ndasdsa\r\nadsadas\e

Regex:

(?:\\r\\n\w*)|(\w+)

Matches:

MATCH 1 'das'

MATCH 2 'rdasdsacxz'

MATCH 3 'ndasdsa'

MATCH 4 'e'

Here's an example: http://regex101.com/r/lE7gI7

Bryan Elliott
  • 4,055
  • 2
  • 21
  • 22