Reputation: 179
I have the regular expression
(GET|POST) (/api/\w+) (HTTP/1\.\d)(?:.*\\r\\n\\r\\n)(\S+)?
which I'm trying to match against HTTP GET and HTTP POST requests. I'm using the helpful regex101.com website to format my regular expression, and according to it, the regular expression should match both the formats I'm seeking.
Here's my regular expression on regex101.com.
However, when I input into Python itself and call re.split()
, (on an input of strings), it doesn't split the POST request. It only splits the GET request. I thought it had something to do with the way regex101 parses \r\n
(CRLF) versus how Python does it, so I double-checked and made sure that in Python, I actually type in \r\n\
inside the regex, and not \\r\\n
, as I did in regex101. Yet it still doesn't work.
How can I get the regular expression to work inside Python?
Upvotes: 1
Views: 56
Reputation: 844
Your'e just missing an additional \r\n
after HTTP/1.0
. This will work:
'POST /api/gettime HTTP/1.0\r\n\r\nContent-Length: 13\r\n\r\n100000+200000'
Upvotes: 1