0

Let's say a format string is given as export_%05u.png, we can create a full string in python by supplying an integer like this s = "export_%05u.png"%1. But If we have the format string and actual string, is it possible to extract the integer somehow?

Formally, these are given: export_%05u.png and export_00111.png and we need to extract 111.

6
  • It depends, for example, '%u1%u" is not reversible. Commented Jul 1, 2023 at 15:11
  • If the format string has only one % conversion, then match the literal characters in the format string to the actual string, remove them from the actual string, and then interpret the remaining characters as the appropriate type. Commented Jul 1, 2023 at 15:13
  • Maybe try Python regular expressions??? Commented Jul 1, 2023 at 15:20
  • If you are looking only for the number within the string, try re.search('[0-9]+', s) Commented Jul 1, 2023 at 15:20
  • 1
    For a table that maps scanf ("printf") tokens to regular expressions, see the documentation for the re module. Commented Jul 1, 2023 at 15:30

0

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.