Question: I'm parsing a html with beautifulsoup. I need to check if a tag have style with something like `border.*:.*px`.

I can find all the tags with style by,

```
soup.find_all(["tr"],style=re.compile(r'border.*:[^:]*px'))

```

But I've to traverse the html in order, so for a tag, how can I check if it has the style of `r'border.*:[^:]*px'`.

I've also refer to [Test if an attribute is present in a tag in BeautifulSoup](https://stackoverflow.com/q/5015483/6521116), use the `has_attr` method of tag, but is seems it not support regular.

```
value = re.compile(r'border.*:[^:]*px')
tag.has_attr("{'style':"+value+"}")

```

but it shows

> 
> 
> ```
> TypeError                                 Traceback (most recent call last)
> <ipython-input-202-1e077ea6ea4c> in <module>
>       1 value = re.compile(r'border.*:[^:]*px')
> ----> 2 tag.has_attr("{'style':"+value+"}")
> 
> TypeError: must be str, not _sre.SRE_Pattern
> 
> ```
> 
>

Answer: 
```py
def foo(tag):
    import re
    tag_style = tag.attrs.get('style')
    return bool(re.search(r'border.*:[^:]*px', tag_style)) if tag_style else False

```
I didn't find a method of BeautifulSoup4 to get it. So I use `re` module as a workaround.

```
import re
border_re = re.compile(r'border.*:[^:]*px')

if tag.has_attr('style') and border_re.search(tag.attrs['style']):

```