我需要一个正则表达式,如果找到大写字母,它可以拆分行。
例子:-
line1 = JOHN levin have fun RAJESH is a good person SAM was ok
期望输出如下
line1 = JOHN levin have fun
RAJESH is a good person
SAM was ok.
是你想要的吗?
$ line1='JOHN levin have fun RAJESH is a good person SAM was ok'
$ sed 's/[A-Z]\+/\n&/g' <<< $line1
JOHN levin have fun
RAJESH is a good person
SAM was ok
请注意,在 JOHN
之前添加了一个换行符,因为它符合您的要求。避免它是另一个问题。另外你的要求是:
I need a regex which could split the lines if Uppercase letter found.
所以预期的输出应该是:
$ sed 's/\([A-Z]\)/\n\1/g' <<< $line1
J
O
H
N levin have fun
R
A
J
E
S
H is a good person
S
A
M was ok
我是一名优秀的程序员,十分优秀!