Skip to content

Instantly share code, notes, and snippets.

@halfak
Created March 12, 2020 14:18
Show Gist options
  • Select an option

  • Save halfak/8ad4ad1ea026eef3bda1fd3ba3a175e5 to your computer and use it in GitHub Desktop.

Select an option

Save halfak/8ad4ad1ea026eef3bda1fd3ba3a175e5 to your computer and use it in GitHub Desktop.
$ python
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> labels_re = r"([^\|\{\{\}\}]+)\|([0-5*])"
>>> my_template = "{{Marca de projeto|3|Biografias|4|Políticos|4|Brasil|3|WP Offline|2|bot=4/20111127|rev=20170714}}"
>>> [(m.group(1), m.group(2)) for m in re.finditer(labels_re, my_template)]
[('Marca de projeto', '3'), ('Biografias', '4'), ('Políticos', '4'), ('Brasil', '3'), ('WP Offline', '2')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment