2

I wanted to match the following string:

strings = iamcool.iplay=ball?end

I want to remove items starting (including the ".") and up till "?", so I want to remove .iplay=ball, so I should have iamcool?end

This is the regex I have:

print re.sub(r'\.\.*?','', strings)

I am not sure how to stop at the "?"

1 Answer 1

2

Use negated character class [^?] which matches anything except ?.

>>> re.sub(r'\.[^?]*', '', strings)
'strings = iamcool?end'
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.