I’m writing a program in python which will deal with user input for football scores. for example:
Newcastle United 4 - 6 Manchester united
above score can also be written as
NUFC 4-6 MUFC and also as newcastle 4-6 manu and so on……
my purpose is to extract the team names and the score:
Newcastle United,4,6,Manchester United.
I need suggestions on how this can be done. One way i could think of is Regular expression but i’m not well versed with regex, so i am seeking help here.
thanks
In general, it looks like a score could be described as a list of 5 items:
and that there may or may not be a space on either side of the hyphen.
The following should work:
The numbers in the call to
group()correspond to the parentheses in the regular expression, from left to right.