8

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

Haider Qureshi
  • 83
  • 1
  • 1
  • 4

2 Answers2

21

The regex pattern is a single string.

'(foo|bar)'
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

how can i search for multiple strings, with OR between them?

Use an alternation operator |

if re.search(r'/wp-(?:admin|includes)/', response):
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274