Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OR operator in re.search for multiple strings in python 3

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

like image 525
Haider Qureshi Avatar asked May 08 '26 13:05

Haider Qureshi


1 Answers

The regex pattern is a single string.

'(foo|bar)'
like image 195
Ignacio Vazquez-Abrams Avatar answered May 11 '26 05:05

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!