-2

I want to get userid from url like:

http://space.bilibili.com/1950746/#!/channel/detail?cid=1757&order=&page=1

and it should be like 1950746.

And here is the code:

url='http://space.bilibili.com/1950746/#!/channel/detail?cid=1757&order=&page=1'
b=userid=re.match(r'\d{7}', url)
print(b)

The result is None.

Ninzero
  • 177
  • 1
  • 12

1 Answers1

0

Using re.match gives an implicit ^ at the beginning of the string. Use re.search to find anywhere in string.

a p
  • 3,098
  • 2
  • 24
  • 46