I am trying to form a regular expression that will match as follows:
- One or more of any character except a colon or space, that then ends with a colon
- Followed by a space
- Followed by one or more number of any character except a colon or space
- Followed directly by
/r/n
As specified above, this is for HTTP GET requests so any of the following would work:
- Host: www.stackoverflow.com/r/n
- a-b-sads&^*@hgsdafAS&FTD: sjal;dfh9S^&D^F&(SDfsdgafs/r/n
and the following would not:
- Host : www.stackoverflow.com
- H:o:s:t: www.stackoverflow.com
- Host: www.:::stackoverflow.com
- Host: www.stackoverflow.com/n
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.