Skip to content

Instantly share code, notes, and snippets.

@Enough7
Last active October 6, 2022 13:32
Show Gist options
  • Save Enough7/c168e3ab8eee5b63852b26bfc253cf95 to your computer and use it in GitHub Desktop.
Save Enough7/c168e3ab8eee5b63852b26bfc253cf95 to your computer and use it in GitHub Desktop.
Regex capture numbers with length 0
Pattern: ((?<=\D|^)\d(?=\D|\n)) // DO NOT forget () or $1 won't capture
Replace/Capture (VsCode): $1
Before:
4
2 4 0 6 0 7 0 13 0 0 0 8 0 0 16 12
0 0 0 8 0 0 12 0 9 0 0 16 0 0 0 6
0 0 0 11 0 4 0 0 0 7 12 0 0 3 13 0
0 0 14 15 0 0 0 0 2 0 0 11 0 8 0 0
5 0 1 0 0 0 10 0 0 0 0 0 0 0 6 0
4 0 8 3 0 0 0 0 13 2 16 1 0 11 14 0
0 0 9 0 0 13 0 1 0 8 0 0 0 0 0 0
0 0 0 0 0 9 2 5 0 0 14 0 0 0 4 7
0 0 0 0 0 0 8 0 0 0 6 12 0 0 3 4
0 3 13 0 14 0 0 10 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 13 10 8 0 2 0
0 0 16 0 0 0 0 0 0 0 0 0 9 5 0 14
11 0 0 0 16 0 0 7 0 0 0 3 14 0 0 0
0 14 0 0 0 0 0 12 0 5 0 0 15 0 11 1
12 0 0 0 0 5 0 0 7 9 1 2 0 16 0 0
0 0 0 13 0 0 0 2 8 0 0 0 4 7 0 5
After:
4
2 4 0 6 0 7 0 13 0 0 0 8 0 0 16 12
0 0 0 8 0 0 12 0 9 0 0 16 0 0 0 6
0 0 0 11 0 4 0 0 0 7 12 0 0 3 13 0
0 0 14 15 0 0 0 0 2 0 0 11 0 8 0 0
5 0 1 0 0 0 10 0 0 0 0 0 0 0 6 0
4 0 8 3 0 0 0 0 13 2 16 1 0 11 14 0
0 0 9 0 0 13 0 1 0 8 0 0 0 0 0 0
0 0 0 0 0 9 2 5 0 0 14 0 0 0 4 7
0 0 0 0 0 0 8 0 0 0 6 12 0 0 3 4
0 3 13 0 14 0 0 10 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 13 10 8 0 2 0
0 0 16 0 0 0 0 0 0 0 0 0 9 5 0 14
11 0 0 0 16 0 0 7 0 0 0 3 14 0 0 0
0 14 0 0 0 0 0 12 0 5 0 0 15 0 11 1
12 0 0 0 0 5 0 0 7 9 1 2 0 16 0 0
0 0 0 13 0 0 0 2 8 0 0 0 4 7 0 5
Add comma after a number but do not bevore space (aka. parse numbers as coordinate)
Pattern: (\d)(?!(\D|\n)) // ?! is negative Lookahead
Replace: $1,
Before:
p cnf 224 38
121
112 212 222
121 211 221
123 213 223
122 212 222
124 214 224
111 121 221
113 123 223
112 122 222
114 124 224
111 121 211
113 123 213
112 122 212
114 124 214
-111 -112
-111 -113
-111 -114
-112 -113
-112 -114
-113 -114
-121 -122
-121 -123
-121 -124
-122 -123
-122 -124
-123 -124
-211 -212
-211 -213
-211 -214
-212 -213
-212 -214
-213 -214
-221 -222
-221 -223
-221 -224
-222 -223
-222 -224
-223 -224
After:
p cnf 2,2,4 3,8
1,2,1
1,1,2 2,1,2 2,2,2
1,2,1 2,1,1 2,2,1
1,2,3 2,1,3 2,2,3
1,2,2 2,1,2 2,2,2
1,2,4 2,1,4 2,2,4
1,1,1 1,2,1 2,2,1
1,1,3 1,2,3 2,2,3
1,1,2 1,2,2 2,2,2
1,1,4 1,2,4 2,2,4
1,1,1 1,2,1 2,1,1
1,1,3 1,2,3 2,1,3
1,1,2 1,2,2 2,1,2
1,1,4 1,2,4 2,1,4
-1,1,1 -1,1,2
-1,1,1 -1,1,3
-1,1,1 -1,1,4
-1,1,2 -1,1,3
-1,1,2 -1,1,4
-1,1,3 -1,1,4
-1,2,1 -1,2,2
-1,2,1 -1,2,3
-1,2,1 -1,2,4
-1,2,2 -1,2,3
-1,2,2 -1,2,4
-1,2,3 -1,2,4
-2,1,1 -2,1,2
-2,1,1 -2,1,3
-2,1,1 -2,1,4
-2,1,2 -2,1,3
-2,1,2 -2,1,4
-2,1,3 -2,1,4
-2,2,1 -2,2,2
-2,2,1 -2,2,3
-2,2,1 -2,2,4
-2,2,2 -2,2,3
-2,2,2 -2,2,4
-2,2,3 -2,2,4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment