Reputation: 357
I am trying to learn Python regular expressions. I have a long string that contains many patterns that look like: #v=xxxxxxxxxx
where x is the variable characters I want.
I was thinking I could use re.findall(r'...', myString)
where ...
is my pattern. That's the part I'm having trouble with. I somehow need to get the next 10 characters after each #v=
.
All help is appreciated :)
Upvotes: 1
Views: 67
Reputation: 8492
You were close! Here's an RE that'll work:
In [1]: import re
In [2]: s = "#v=yyyyyyyyyy #v=xxxxxxxxxx #v=zzzzzzzzzz"
In [3]: re.findall(r'#v=(\w{10})', s)
Out[3]: ['yyyyyyyyyy', 'xxxxxxxxxx', 'zzzzzzzzzz']
Upvotes: 1