Last active
April 27, 2024 06:53
-
-
Save servel333/ae37535aa3eda18b454ab3ba1311555e to your computer and use it in GitHub Desktop.
Regex to increment a number in text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Regex to increment a number in text. | |
# Source: https://stackoverflow.com/a/31599758/761771 | |
echo " 0 1 2 3 7 8 9 10 19 99 109 199 909 999 1099 1909" | | |
perl -pe 's/\b([0-9]+)\b/0$1~01234567890/g' | | |
perl -pe 's/\b0(?!9*~)|([0-9])(?=9*~[0-9]*?\1([0-9]))|~[0-9]*/$2/g' | |
# Output > 1 2 3 4 8 9 10 11 20 100 110 200 910 1000 1100 1910 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment