Last active
July 5, 2019 04:11
-
-
Save evandrocoan/0a260ed741f5f13f22741ce102eb10b4 to your computer and use it in GitHub Desktop.
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/bash | |
outversions=" | |
Things 17.16 I am not 12.23.1 interested | |
36.35.17 | |
35.34.16 | |
24.23.5 | |
19.18 | |
3. | |
6.5 | |
38.37.19 | |
Things 17.16 I am not 12.23.1 interested | |
27.26.8 | |
10.9 | |
12.11 | |
34.33.15 | |
39.38.20 | |
31.30.12 | |
25.24.6 | |
26.25.7 | |
9.8 | |
30.29.11 | |
21.20.2 | |
22.21.3 | |
"; | |
function matchwithpythonregex() { | |
# you cannot indent this! | |
pythonprogram="\ | |
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
import re; | |
import sys; | |
import codecs | |
# https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python | |
ESCAPE_SEQUENCE_RE = re.compile( | |
r''' | |
( \\\\U........ # 8-digit hex escapes | |
| \\\\u.... # 4-digit hex escapes | |
| \\\\x.. # 2-digit hex escapes | |
| \\\\[0-7]{1,3} # Octal escapes | |
| \\\\N\{[^}]+\} # Unicode characters by name | |
| \\\\[\\\\'\"abfnrtv] # Single-character escapes | |
)''', re.UNICODE | re.VERBOSE) | |
def decode_escapes(inputstring): | |
def decode_match(match): | |
return codecs.decode( match.group(0), 'unicode-escape' ); | |
return ESCAPE_SEQUENCE_RE.sub( decode_match, inputstring ); | |
versions = ''.join( sys.argv[1:] ); | |
versions = decode_escapes( versions ); | |
# print( 'versions %s' % versions ); | |
for line in versions.split( '\n' ): | |
# print( 'line %s' % line ); | |
result = re.search( r'^((?:(?:\d)\.?)+)', line ); | |
if result: | |
print( result.group( 1 ) ); | |
"; | |
versions="${1}"; | |
python -c "${pythonprogram}" "${versions}"; | |
} | |
resultlines="$(matchwithpythonregex "${outversions}")"; | |
printf "The resultlines are:\\n%s\\n" "${resultlines}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment