Using OR operator in re.search for multiple strings in python 3
22,015
Solution 1
The regex pattern is a single string.
'(foo|bar)'
Solution 2
how can i search for multiple strings, with OR between them?
Use an alternation operator |
if re.search(r'/wp-(?:admin|includes)/', response):
Author by
Admin
Updated on February 11, 2020Comments
-
Admin about 4 years
Sorry if this is already been asked, though i couldn't find it. Im trying to detect if a website uses wordpress. here is the sample code.
url = input("Please enter the URL") if 'http://' in url: append = url else: append = 'http://' + url r = requests.get(append + "/robots.txt") response = r.text if re.search(('/wp-includes/') | ('/wp-admin/'), response): print("{0} --> Its Wordpress ".format(append)) sys.exit(0)
It says | operator cannot be used, in
if re.search(('/wp-includes/') | ('/wp-admin/'), response):
how can i search for multiple strings, with OR between them? i also tried using 'or' and tried this
if re.search('/wp-includes/' , '/wp-admin/'), response):
Thanks