quick regex question

Discussion in 'Python' started by Matt Price, Oct 28, 2004.

  1. Matt Price

    Matt Price Guest

    hi folks,

    this is surely trivial, but can'f figure it out. I wnat to replace:

    'string with spaces'
    with
    'StringWithSpaces'

    so I tried this:

    s = 'string with spaces'
    pat = ' (.)'
    t = re.sub(pat, upper, s)

    I know this isn't quite right, I expect it to return:
    'String With Spaces'

    instead I get an error:
    t = re.sub(' (.)', upper, s)
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.3/sre.py", line 143, in sub
    return _compile(pattern, 0).sub(repl, string, count)
    File "/usr/lib/python2.3/string.py", line 64, in upper
    return s.upper()
    AttributeError: upper

    what am I doing wrong?

    matt


    -------------------------------------------
    Matt Price
    History Department, University of Toronto
    (416) 978-2094
    --------------------------------------------

    please don't use the following addresses:
     
    Matt Price, Oct 28, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    11
    Views:
    938
  2. Steven Bethard

    Re: quick regex question

    Steven Bethard, Oct 28, 2004, in forum: Python
    Replies:
    5
    Views:
    626
    Peter Otten
    Oct 29, 2004
  3. Robert Brewer

    RE: quick regex question

    Robert Brewer, Oct 28, 2004, in forum: Python
    Replies:
    0
    Views:
    647
    Robert Brewer
    Oct 28, 2004
  4. Replies:
    3
    Views:
    832
    Reedick, Andrew
    Jul 1, 2008
  5. Jürgen Exner

    Re: Quick perl script-regex question

    Jürgen Exner, Nov 4, 2011, in forum: Perl
    Replies:
    0
    Views:
    2,016
    Jürgen Exner
    Nov 4, 2011
Loading...

Share This Page