Reputation: 423
I would like some help writing this as a regular expression since I know the basics but not sure how to translate it into RegEx.
"command:argname-argvalue:arg2name-arg2val!!END!SENDTO:IP.ADD.RE.SS"
Command: specific keyword that determines the action I must handle. Must be there.
Arguments: (shown there 2, but not limited to 2, as many as wanted) argument name
and argument value
, separated by a hyphen. At least one.
!!END!
declares the end of the expression and must be there.
SENDTO:000.000.000.000
optional argument and has to match SENDTO:
and then a valid IP address.
I then want to store the command, argument name and argument value pairs and, if included, the user ip, in a Python implementation.
I know this sounds like homework but please guys I have now idea how to do this and I would expend hours in trying to learn advanced RegEx. If you could help me, I would be glad to receive your help.
Upvotes: 2
Views: 103
Reputation: 107317
what about the following regex ?
[\w ?]+:\w+-\d+:\w+-\d+!!END!(\\\[)?\w+:\b(?:\d{1,3}\.){3}\d{1,3}\b(\\\])?
this match some sentence like following :
command:argname-123:arg2name-340234!!END!\[SENDTO:000.000.000.000\]
Upvotes: 1