Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
^\n|\n$
/
g
Input 1
1
New
import regex as re from colorama import Fore, Back def red(s): return Back.RED + s + Back.RESET with open('/tmp/1.py', 'r') as f: data = f.read() print( re.sub(r'(^\n|\n$)', red(r'\1'), data) )
Substitution
import regex as re from colorama import Fore, Back def red(s): return Back.RED + s + Back.RESET with open('/tmp/1.py', 'r') as f: data = f.read() print( re.sub(r'(^\n|\n$)', red(r'\1'), data) )