Skip to main content
added 386 characters in body
Source Link

R, 6060 55 bytes

\(s)gsub("([a-z])([^az][^a-z]*)([a-z]?)","\\U\\1\\2\\L\\3""\\U\\1\\L\\2",s,T,T)

Attempt This Online!Attempt This Online!

Some explanation: This solution uses one single gsub and a regex which matches the pairs of letters: (1) the first letter, (2) followed by zero or more non-letter characters in-between and (32) an optional second letter. Accordingly, the 1st matchcatching group is capitalized and the 3rd2nd one is converted to the lowercase. Two positional arguments stand for ignore.case = TRUE and perl = TRUE.

R, 60 bytes

\(s)gsub("([a-z])([^a-z]*)([a-z]?)","\\U\\1\\2\\L\\3",s,T,T)

Attempt This Online!

Some explanation: This solution uses one single gsub and a regex which matches the pairs of letters: (1) the first letter, (2) zero or more non-letter characters in-between and (3) an optional second letter. Accordingly, the 1st match is capitalized and the 3rd one is converted to the lowercase. Two positional arguments stand for ignore.case = TRUE and perl = TRUE.

R, 60 55 bytes

\(s)gsub("([a-z][^a-z]*)([a-z]?)","\\U\\1\\L\\2",s,T,T)

Attempt This Online!

Some explanation: This solution uses one single gsub and a regex which matches the pairs of letters: (1) the first letter followed by zero or more non-letter characters and (2) an optional second letter. Accordingly, the 1st catching group is capitalized and the 2nd one is converted to the lowercase. Two positional arguments stand for ignore.case = TRUE and perl = TRUE.

Source Link

R, 60 bytes

\(s)gsub("([a-z])([^a-z]*)([a-z]?)","\\U\\1\\2\\L\\3",s,T,T)

Attempt This Online!

Some explanation: This solution uses one single gsub and a regex which matches the pairs of letters: (1) the first letter, (2) zero or more non-letter characters in-between and (3) an optional second letter. Accordingly, the 1st match is capitalized and the 3rd one is converted to the lowercase. Two positional arguments stand for ignore.case = TRUE and perl = TRUE.