Reputation: 804
I am trying to form a regular expression that will match as follows:
/r/n
As specified above, this is for HTTP GET requests so any of the following would work:
and the following would not:
I am currently using re.compile(r"^.{1,}: .{1,}[/r/n]$")
but am not sure how to exclude colons from certain subsets of the string.
EDIT: I believe what I want to start with is ^
to signify the beginning of a string. Then, I want one or more number of any character except a colon so .{1,}
, but I am not sure how I would exclude colon from this list. Then I want a colon and a space, so just :
, and then any character except a colon .{1,}
with the same problem as before of excluding colons. Finally, I want it to end with [\r\n]$
. This still does not seem to work, even if I exclude the no colon character requirement. So something like ^.{1,}: .{1,}\r\n$
, but I still need to figure out how to exclude colons.
Upvotes: 1
Views: 71
Reputation: 974
In total, the following should work
^([^ :]+): ([^ :]+)$
giving Host in group 1 and the url in group 2
Test it here
Upvotes: 1