Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

remove from 1st upper case alphabetical character to end of string and and special character

I have a small exercise that required me to remove all special character and the 1st upper case alphabetical character to end of string except dots [.] and hyphens [-] .I tried the solution here https://www.geeksforgeeks.org/remove-uppercase-lowercase-special-numeric-and-non-numeric-characters-from-a-string/
The string below example is one of the example

import re

def removingUpperCaseCharacters(str):
    regex = "[A-Z]"
    return (re.sub(regex, "", str))
def removingSpecialCharacters(str):
 
    # Create a regular expression
    regex = "[^.A-Za-z0-9]"
 
    # Replace every matched pattern
    # with the target string using
    # sub() method
    return (re.sub(regex, "", str))
str = "teachert.memeCon-Leng:"
print("After removing uppercase characters:",
       removingUpperCaseCharacters(str))
print("After removing special characters:",
       removingSpecialCharacters(str))

The output is

After removing uppercase characters: teachert.memeontent-ength:
After removing special characters: teachert.memeContentLength

The ouput I want is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

teachert.meme

>Solution :

You could replace one of your functions as follows:

def removingUpperCaseCharacters(str):
    i = 0
    while i < len(str) and (ord('A') > ord(str[i]) or ord('Z') < ord(str[i])):
        i += 1
    return str[:i]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading