Python string match


Question

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

1
14
5/11/2013 5:00:57 PM

Accepted Answer

if "subject" in mystring.lower():
  # do something
34
7/28/2010 9:14:18 AM

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()

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon