regex - Python: convert variable-like strings to class-like strings -


this question has answer here:

i'm having trouble trying create function can job. objective convert strings

  • one one
  • hello_world helloworld
  • foo_bar_baz foobarbaz

i know proper way using re.sub, i'm having trouble creating right regular expressions job.

you can try this:

>>> s = 'one' >>> filter(str.isalnum, s.title()) 'one' >>> >>> s = 'hello_world' >>> filter(str.isalnum, s.title()) 'helloworld' >>>  >>> s = 'foo_bar_baz' >>> filter(str.isalnum, s.title()) 'foobarbaz' 

relevant documentation:


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -