我想匹配和組任一列出的單詞:正則表達式匹配空字符串?
aboutus/
,race/
,cruise/
,westerlies/
,weather/
,reach/
,gear/
或empty_string
這裏是一個解決方案,但它不會匹配empty_string:
^(aboutus|race|cruise|westerlies|weather|reach|gear)/$
所以我的問題是:如何在此匹配中包含空字符串?
我仍然沒有得到一個很好的解決方案。
因此,我特別爲empty_string添加了一個正則表達式:即^$
。
注意:這些正則表達式適用於django urls.py
。
更新:這將是更好的,如果捕獲組不包含/
不會'^(公司簡介|比賽|巡航|西風|天氣|達到|齒輪|)/ $'工作? – njzk2
'^(aboutus | race | cruise | westerlies | weather | reach | gear]?/ $' – karthikr
空字符串仍然會跟着'/'嗎? – Drewness