Created
August 5, 2022 09:48
-
-
Save AptiviCEO/efb89e855272f6077b7c4f1d6340933e to your computer and use it in GitHub Desktop.
Filter and find VT sequences in string
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
import re | |
import argparse | |
def filterVTSequences(text): | |
pattern = '^(\x9D|\x1B\]).+(\x07|\x9c)|\x1b [F-Nf-n]|\x1b#[3-8]|\x1b%[@Gg]|\x1b[()*+][A-Za-z0-9=`<>]|\x1b[()*+]\"[>4?]|\x1b[()*+]%[0-6=]|\x1b[()*+]&[4-5]|\x1b[-.\/][ABFHLM]|\x1b[6-9Fcl-o=>\|\}~]|(\x9f|\x1b_).+\x9c|(\x90|\x1bP).+\x9c|(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]|(\x9e|\x1b\^).+\x9c|\x1b[DEHMNOVWXYZ78]$' | |
result = re.sub(pattern, '', text) | |
print(result) | |
parser = argparse.ArgumentParser() | |
parser.add_argument('text', type=str, help="Text to filter") | |
args = parser.parse_args() | |
filterVTSequences(args.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
import re | |
import argparse | |
def findVTSequences(text): | |
pattern = '^(\x9D|\x1B\]).+(\x07|\x9c)|\x1b [F-Nf-n]|\x1b#[3-8]|\x1b%[@Gg]|\x1b[()*+][A-Za-z0-9=`<>]|\x1b[()*+]\"[>4?]|\x1b[()*+]%[0-6=]|\x1b[()*+]&[4-5]|\x1b[-.\/][ABFHLM]|\x1b[6-9Fcl-o=>\|\}~]|(\x9f|\x1b_).+\x9c|(\x90|\x1bP).+\x9c|(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]|(\x9e|\x1b\^).+\x9c|\x1b[DEHMNOVWXYZ78]$' | |
result = [x.group() for x in re.finditer(pattern, text)] | |
print(result) | |
parser = argparse.ArgumentParser() | |
parser.add_argument('text', type=str, help="Text to find VT sequences on") | |
args = parser.parse_args() | |
findVTSequences(args.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment