1

I am a newbie in python. I am coding in python 2.7. I have two strings that look like:

a = ": Handle reset full zone for zone management send to individual zone case. Contact [email protected]"
b = " 123andle reset [full] zone for zone >= management: send to individual zone case. Robotics: 431."

How do I extract the whole string except for the first colon and first space(: ) in a and the first space in b? So everything else other than those two things should be printed. Here is how it should look like:

Handle reset full zone for zone management send to individual zone case. Contact [email protected]
123andle reset [full] zone for zone >= management: send to individual zone case. Robotics: 431.

I am allowed to use only one algorithm to parse both strings a and b. So one regex pattern algorithm shall be used to parse both and give the correct result. Note that the sentence can look like anything and contain any type of alphanumeric or non alphanumeric characters and so all of it should be printed.

a = ": Handle reset full zone for zone management send to individual zone case. Contact [email protected]"
b = " 123andle reset [full] zone for zone >= management: send to individual zone case. Robotics: 431."
str = []
str.append(a)
str.append(b)
title_regex = "\w+"

for str_in in str:
    title = re.findall(title_regex, str_in)
    print(title)

But this implementation is not right as I get a list of words where the whitespace is not considered and also the [] and some non alphanumeric characters a re also not considered.

1 Answer 1

1

You don't need regex for this. Just do a.lstrip(" :"),

FYI, Python 2 has been outdated for a decade, and you shouldn't be learning it if you're a beginner. Python 3 is vastly superior in every way. Also, don't name your variables after a builtin(str).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.