这是我的输入和期望的输出。实现此目标的最佳方法是什么?
输入:
Agilent Technologies Inc
A
NEW YORK STOCK EXCHANGE, INC.
Wide
Medium
1.47
Exemplary
ABB Ltd ADR
ABB
NEW YORK STOCK EXCHANGE, INC.
Wide
Medium
0.97
Standard
Ambev SA ADR
ABEV
NEW YORK STOCK EXCHANGE, INC.
Wide
Medium
0.85
Exemplary
ABB Ltd
ABLZF
OTC LINK ATS - OTC MARKETS
–
Wide
Medium
–
–
Auckland International Airport Ltd
ACKDF
OTC LINK ATS - OTC MARKETS
–
Wide
Medium
–
–
请注意,其中一些有 8 行段落,而有些则有 7 行。
输出:
'A', 'ABB', 'ABEV', 'ABLZF', 'ACKDF'
谢谢!
答案1
- Ctrl+H
- 找什么:
^([A-Z]{1,5})$|^.*\R?
- 用。。。来代替:
$1
- 查看 相符
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
^ # beginning of line
( # start group 1
[A-Z]{1,5} # 1 up to 5 capital letters
) # end group
$ # end of line
| # OR
^ # beginning of line
.* # 0 or more any character but linebreak
\R? # any kind of linebreak (i.e. \r, \n, \r\n), optional
替代品:
$1 # content of group 1, the capital letters
截图(之前):
截图(之后):