问题
我想将itertools
类添加到两种不同类型的页面中:
1)与此网址匹配的网页:from collections import Counter
from itertools import chain
c = Counter(mylist)
c.subtract(chain.from_iterable(mydictlist))
# In 3.3+, easiest way to remove 0/negative counts
c = +c
# In pre-3.3 Python, change c = +c to get the same effect slightly less efficiently
c += Counter()
2)网址中body
之后有任何内容的网页:example.com/shop/
到目前为止,我已经使用此代码解决了第一个问题:
/shop/
但是,这也会将example.com/shop/asdfjkl, example.com/shop/item-2342, etc.
类添加到以 if(window.location.href.match('example.com/shop/')){
jQuery('body').addClass('shop');
}
开头的任何网址(请参阅问题#2)
问题
如何在 shop
之后的单词中添加单独的example.com/shop/
类?
答案 0 :(得分:2)
您可以使用正则表达式:
if( window.location.href.match(new RegExp('example.com/shop/.+')) ) {
$('body').addClass('shop-item');
} else if (window.location.href.match('example.com/shop/')) {
$('body').addClass('shop');
}