Regular expressions question

Victor Polukcht vpolukcht at gmail.com
Tue Jan 16 12:59:28 EST 2007


Great thnx. It works.

On Jan 16, 6:02 pm, Wolfgang Grafen <wolfgang.gra... at marconi.com>
wrote:
> Victor Polukcht wrote:
> > I have 2 strings:
>
> > "Global               etsi3   *200 ok            30   100% 100%
> > Outgoing"
> > and
> > "Global               etsi3   *   4 ok             30   100% 100%
> > Outgoing"
>
> > The difference is "*200" instead of "*  4". Is there ability to write a
> > regular expression that will match both of that strings?---------------------------- x.py begin --------
> import re
>
> s1 = "Global               etsi3   *200 ok            30   100% 100% Outgoing"
> s2 = "Global               etsi3   *   4 ok             30   100% 100% Outgoing"
>
> re_m = re.compile( "^"
>                     "(\S+)"         # Global
>                     "\s+"
>                     "(\S+)"         # etsi3
>                     "\s+"
>                     "((\*)\s*(\d+))"    # *200 *  4
>                     "\s+"
>                     "(\S+)"         # ok
>                     "\s+"
>                     "(\S+)"         # 30
>                     "\s+"
>                     "(\S+)"         # 100%
>                     "\s+"
>                     "(\S+)"         # 100%
>                     "\s+"
>                     "(\S+)"         # Outgoing
>                     "$"
>                   ).match
>
> print "match s1:", re_m(s1).groups()
> print "match s2:", re_m(s2).groups()
> ----------------------------- x.py file end ---------
>
> % python x.py
> match s1: ('Global', 'etsi3', '*200', '*', '200', 'ok', '30', '100%', '100%', 'Outgoing')
> match s2: ('Global', 'etsi3', '*   4', '*', '4', 'ok', '30', '100%', '100%', 'Outgoing')




More information about the Python-list mailing list