0

Imagine I have the text: http://127.0.0.1:8000/?page=2#section0

If my string contains ?page=, I want to be able to get 2 from the string (and not 2#section0, just the number after ?page=).

For instance, if I have http://127.0.0.1:8000/?page=32#section0, I ought to be able to get 32.

What's the fastest way to do that?

1 Answer 1

1

The easiest way would be with a regular expression: (\d) means "digit", (\d+) means "1 or more digit" and page=(\d+) means "1 or more digit following the text page=. In Python,

import re
re.search('page=(\d+)', yourstring).group(1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.