Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th April 2023, 10:32   #1  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,753
How to strip extended XTerm ANSI Escape sequences with RegEx?

In general, an ANSI Escape sequence is made of
  • the ESC character (ASCII 27 = 0x1B)
  • usually the [ character
  • optional number parameters, separated by ; semicola
  • usually one alphanumeric letter

These strings could be filtered with a regular expression substitution for e.g. sed like:

Code:
s/\x1b\[[0-9;]*[a-zA-Z]//g
But ... XTerm (in mintty) supports a few more custom extensions which do not only start with the common [, some also start with ] or (.

I tried several ways to substitute the \[ with a list of \[, \] and \(, but I can't get it working correctly...

If you want to test a solution you would like to recommend, here is a small sample.
__

PS: Some progress ... I could combine patterns starting with ESC and ([ or () using

Code:
s/\x1b[[(][0-9;]*[a-zA-Z]//g
But I'm still missing the ESC ]0; pattern as alternative, which does not close with an alphanumeric letter.
__

PPS: I believe I got it.

The pipe | needs to be escaped to be recognised as logical OR inside the sed parameter, but only in the live editor; in a shell script it doesn't.

Code:
s/\x1b[[(][0-9;]*[a-zA-Z]|\x1b\][0-9];//g
Thanks to the GNU sed live editor
__________________

New German Gleitz board
MediaFire: x264 | x265 | VPx | AOM | Xvid

Last edited by LigH; 17th April 2023 at 12:18.
LigH is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:05.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.