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
Post a Comment