2015-02-11 31 views
0

對不起,如果這已被問到,但我找不到它。我試圖檢測一個網站是否使用WordPress。這裏是示例代碼。在re.search中對Python中的多個字符串使用OR運算符3

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) 

它說|運營商不能使用,在

if re.search(('/wp-includes/') | ('/wp-admin/'), response): 

如何搜索多個字符串,與他們之間的OR?我也嘗試過使用「或」並試用了此

if re.search('/wp-includes/' , '/wp-admin/'), response): 

感謝

回答

3

正則表達式模式是一個字符串。

'(foo|bar)' 
0

我如何可以搜索多個字符串,帶或它們之間?

使用的交替操作者|

if re.search(r'/wp-(?:admin|includes)/', response): 
相關問題