I'm having a terrible time with regular expressions, possibly because I'm using a python2 reference, but maybe not. For example how would I find \s\w within a string and then change that character?
JoshuaBurleson 23 Posting Whiz
Recommended Answers
Jump to PostDo you mean searching for first letter of word:
re.findall('\s\w', r"For example how would I find \s\w within a string and then change that character?")
Jump to PostYou would use .title() ;)
Not so special, maybe but this leaves all but last word uncapitalized.
sa ='Secret agent' m = re.match(r'(.*\s)(\w*)', sa) >>> m.groups() ('Secret ', 'agent') >>> ''.join(word.capitalize() for word in m.groups()) 'Secret Agent' >>> sa ='Secret agent office' >>> m.groups() ('Secret ', …
All 6 Replies
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
JoshuaBurleson 23 Posting Whiz
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
JoshuaBurleson 23 Posting Whiz
JoshuaBurleson 23 Posting Whiz
JoshuaBurleson 23 Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.