14

If a string contains *SUBJECT123, how do I determine that the string has subject in it in python?

1
  • What is the relevance of "If a string contains *SUBJECT123"? Do you mean "How do I do a case-insensitive search"? Commented Jul 28, 2010 at 8:59

4 Answers 4

34
if "subject" in mystring.lower():
  # do something
Sign up to request clarification or add additional context in comments.

1 Comment

you can use the lower() method
12

If you want to have subject match SUBJECT, you could use re

import re
if re.search('subject', your_string, re.IGNORECASE)

Or you could transform the string to lower case first and simply use:

if "subject" in your_string.lower()

Comments

7

Just another way

mystring.find("subject")

the above answers will return true if the string contains "subject" and false otherwise. While find will return its position in the string if it exists else a negative number.

Comments

1
if "*SUGJECT123" in mystring and "subject" in mystring:
    # do something

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.