Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python string match

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

like image 366
Rajeev Avatar asked Jul 28 '10 08:07

Rajeev


People also ask

How do you match a string in Python?

Use the string method startswith() for forward matching, i.e., whether a string starts with the specified string. You can also specify a tuple of strings. True is returned if the string starts with one of the elements of the tuple, and False is returned if the string does not start with any of them.

How do I check if a string matches in Python?

Python strings equality can be checked using == operator or __eq__() function. Python strings are case sensitive, so these equality check methods are also case sensitive.

What does match () do in Python?

match() function of re in Python will search the regular expression pattern and return the first occurrence. The Python RegEx Match method checks for a match only at the beginning of the string. So, if a match is found in the first line, it returns the match object.


1 Answers

if "subject" in mystring.lower():
  # do something
like image 57
ghostdog74 Avatar answered Sep 29 '22 21:09

ghostdog74