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. Advertisements

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:
    1,195
  2. Steven Bethard

    Re: quick regex question

    Steven Bethard, Oct 28, 2004, in forum: Python
    Replies:
    5
    Views:
    816
    Peter Otten
    Oct 29, 2004
  3. Replies:
    3
    Views:
    1,112
    Reedick, Andrew
    Jul 1, 2008
  4. Jürgen Exner

    Re: Quick perl script-regex question

    Jürgen Exner, Nov 4, 2011, in forum: Perl
    Replies:
    0
    Views:
    2,245
    Jürgen Exner
    Nov 4, 2011
  5. Neowulf

    Quick Regex Query

    Neowulf, Dec 23, 2005, in forum: Ruby
    Replies:
    5
    Views:
    231
    Robert Klemme
    Dec 27, 2005
  6. Marv

    Quick Regex Subst question

    Marv, Dec 28, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    410
    Eric Amick
    Dec 28, 2003
  7. a quick regex question

    , Dec 1, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    458
    Dr.Ruud
    Dec 4, 2006
  8. a quick regex question

    , Dec 1, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    467
    John Bokma
    Dec 1, 2006
Loading...