i have string like this
603 - CELLULITIS W/O MCC
i want to convert it to
CELLULITISWOMCC
in python using regex my previous attempts
s= re.sub(r"(\b|\s+\-?|^\-?)(\d+\s[-]\s|\d*\.\d+)\b","",s)
which lead me to this CELLULITIS W/O MCC
Join Stack Overflow to learn, share knowledge, and build your career.
Since you want to remove non capital alphabet characters, a negation regex would work much better than a positive regex. Search for characters that are not capital alphabets and replace with empty string.
You may try like so:
import re
s1 = "603 - CELLULITIS W/O MCC "
s2 = re.sub(r'[^A-Z]+', r'', s1)
print s2
Output:
CELLULITISWOMCC
Regex:
[^A-Z]+
- Match 1 or more characters which are not from A
to Z
[^A-Z]
matches any character which is not a letter. Hope this helps. – 9000 Feb 9 '17 at 4:28