Q:

string match using re in python re.search

search() to match the string. Bellow is my code
import re

s = "hello world"

if re.search(r'hello world other exter string',s):
    print 'match success'
else:
    print 'no match'

in the above code it gives me no match. Even though "hellow world" is a part of the given string. i tried using re.match() also but getting the same result.

A:

Your order of arguments is wrong. It should be re.search(pattern, string):
if re.search(s, 'hello world other exter string'):
    print 'match success'
else:
    print 'no match'

[OUTPUT]
match success

Furthermore, as @thefourtheye stated, a simple if substring in string: would suffice. Regex is for detecting patterns in string. Say for example you wanted to find all the 5 letter words (although this can also be done without regex):
>>> print re.findall(r'\b[a-zA-Z]{5}\b', 'hello world other exter string')
['hello', 'world', 'other', 'exter']

