Skip to content

Instantly share code, notes, and snippets.

@fhightower
Created May 15, 2017 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhightower/2d0681db7576ff838ef6138041ba51f9 to your computer and use it in GitHub Desktop.
Save fhightower/2d0681db7576ff838ef6138041ba51f9 to your computer and use it in GitHub Desktop.
Increment :emphasize-lines: numbers
import os
import re
# read a file or define a variable that is a string here...
# this defines how much you would like to add to the values (can be a negative number)
delta = 2
matches = re.findall(':emphasize-lines: (.*)', file_text)
# increment intervals appropriately
for match in matches:
emphasis_intervals = list()
for range_ in match.split(","):
new_nums = list()
for num in range_.split("-"):
new_nums.append(str(int(num) + delta))
emphasis_intervals.append("-".join(new_nums))
print("New intervals: {}".format(,".join(emphasis_intervals)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment