user2825425 user2825425 - 3 months ago 6
Python Question

Regular Expression to match "\\r"

I'm having trouble writing a regex that matches these inputs:

1.

\\r


2.
\\rSomeString



I need a regex that matches
\\r

AER AER
Answer

Escape the back slashes twice. String's interpret \ as a special character marker.

Use \\\\r instead. \\ is actually interpreted as just \.

EDIT: So as per the comments you want any string that starts with \\r with any string after it. The regex pattern is as follows:

(\\\\r\S*)

\\\\r is the string you want at the start and \S* says any non-white space (\S) can come after any number of times (*).

Comments