[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Lovepython015/Python/master/Article/PythonBasis/python14/6.md [Back]  [Original]

# re.match   re.search

**re.match **



```python
re.match(pattern, string, flags=0)
```

re.match match()  none


**re.search **



```Python
re.search(pattern, string, flags=0)
```

re.search 

re.match  re.search 

|     |                                                      |
| ------- | -------------------------------------------------------- |
| pattern |                                          |
| string  |                                            |
| flags   |  |



re.match  None re.search 

re.match  re.search   re.findall

 re.search  re.findall   



```python

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

# 

import re

a = 'a8c49ef606e0e1f3ee39a7b219b5c05e.jpg [a8c49ef606e0e1f3ee39a7b219b5c05e.jpg]'

#  re.search
search = re.search('(.*) [(.*)]', a)
# group(0) 
print(search.group(0))
print(search.group(1))

#  re.findall
findall = re.findall('(.*) [(.*)]', a)
print(findall)

#  img 
re_search = re.search('', a)
#  img
print(re_search.group(1))
# 
print(re_search.group(2))
#  img 
print(re_search.group(1, 2))
#  groups
print(re_search.groups())

```



```txt
a8c49ef606e0e1f3ee39a7b219b5c05e.jpg [a8c49ef606e0e1f3ee39a7b219b5c05e.jpg]
https://s-media-cache-ak0.pinimg.com/originals/a8/c4/9e/a8c49ef606e0e1f3ee39a7b219b5c05e.jpg
['https://s-media-cache-ak0.pinimg.com/originals/a8/c4/9e/a8c49ef606e0e1f3ee39a7b219b5c05e.jpg']
img
https://s-media-cache-ak0.pinimg.com/originals/a8/c4/9e/a8c49ef606e0e1f3ee39a7b219b5c05e.jpg
('img', 'https://s-media-cache-ak0.pinimg.com/originals/a8/c4/9e/a8c49ef606e0e1f3ee39a7b219b5c05e.jpg')
('img', 'https://s-media-cache-ak0.pinimg.com/originals/a8/c4/9e/a8c49ef606e0e1f3ee39a7b219b5c05e.jpg')
```


python  Python  Python 

githubhttps://github.com/TwoWater/Python/blob/master/python14/%E5%B8%B8%E7%94%A8%E7%9A%84%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F.md

 start https://github.com/TwoWater/Python  Python 

![http://twowater.com.cn/images/20171204192251900.gif](http://twowater.com.cn/images/20171204192251900.gif)

Web Proxy Viewer  |  New URL  |  Original Page