![如何删除 1 个字符前后的文本](https://linux22.com/image/1576189/%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4%201%20%E4%B8%AA%E5%AD%97%E7%AC%A6%E5%89%8D%E5%90%8E%E7%9A%84%E6%96%87%E6%9C%AC.png)
例如我有:
Apple:123456789:pear
watermelon:57952161354:kfc
我如何删除“:”之前和之后的文本以获得以下内容:
123456789
57952161354
答案1
- Ctrl+H
- 找什么:
^[^:]+:([^:]+):[^:]+$
- 用。。。来代替:
$1
- 检查环绕
- 检查正则表达式
- Replace all
解释:
^ # beginning of line
[^:]+: # 1 or more any character that is not colon followed by 1 colon
([^:]+) # group 1, 1 or more any character that is not colon
:[^:]+ # 1 colon followed by 1 or more any character that is not colon
$ # end of line
替代品:
$1 # content of group 1 (i.e. the digits)
给定示例的结果:
123456789
57952161354