views:

63

answers:

4

If a string contains *SUBJECT123 how to determine that the string has subject in it in python

+3  A: 
if "subject" in mystring.lower():
  # do something
ghostdog74
Is it case insensitive?
Rajeev
you can use the lower() method
ghostdog74
+1  A: 

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()
Felix Kling
A: 
if "*SUGJECT123" in mystring and "subject" in mystring:
    # do something
Douglas Leeder
A: 

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.

anand