小编jos*_*ski的帖子

如果匹配模式,则删除该行中的换行符

让模式是字符串"爱"

输入

This is some text
Love this or that
He is running like a rabbit
Run Code Online (Sandbox Code Playgroud)

产量

This is some text
Love this or thatHe is running like a rabbit
Run Code Online (Sandbox Code Playgroud)

我注意到sed是非常不愉快的删除换行符,任何想法?

awk grep sed tr

8
推荐指数
1
解决办法
9919
查看次数

Emacs regexp取代了情况

在emacs上

假设我有这样的文字:

abcd abcd. 23在哪里. 2捕捉很重要

随着\. [[:digit:]]我可以捕捉模式,但如何没有.

输出应该是abcd abcd 23.

regex emacs replace

5
推荐指数
1
解决办法
90
查看次数

按字符拆分泰语文本

不是通过单词边界,这是可以解决的.

例:

#!/usr/bin/env python3  
text = '?????????????'  
for char in text:  
    print(char)  
Run Code Online (Sandbox Code Playgroud)

这将产生:






这显然不是理想的输出.有任何想法吗?

可移植的文本表示形式是:

text = u'\u0e40\u0e21\u0e37\u0e48\u0e2d\u0e41\u0e23\u0e01\u0e40\u0e23\u0e34\u0e48\u0e21'
Run Code Online (Sandbox Code Playgroud)

python unicode python-3.x thai

5
推荐指数
1
解决办法
2373
查看次数

0
推荐指数
1
解决办法
162
查看次数

Linux取代换行

输入

aaaa
bbbb
cccc
Run Code Online (Sandbox Code Playgroud)

产量

aaaa
< _jupijuice_ >
bbbb
< _jupijuice_ >
cccc
< _jupijuice_ >
Run Code Online (Sandbox Code Playgroud)

简单来说,将\n替换为\n < jupijuice > \n

linux awk sed

0
推荐指数
1
解决办法
192
查看次数

python re.sub with variable

输入文本:

Ell &#233;s la v&#237;ctima que expia els nostres pecats, i no tan sols els nostres, sin&#243; els del m&#243;n sencer.  
Run Code Online (Sandbox Code Playgroud)

预期产量:

Ell és la víctima que expia els nostres pecats, i no tan sols els nostres, sinó els del món sencer.
Run Code Online (Sandbox Code Playgroud)

已知事实:unichr(233)=é

现在我有

re.sub('&#([^;]*);', r'unichr(int(\1))', inputtext, flags=re.UNICODE)
Run Code Online (Sandbox Code Playgroud)

当然不工作,不知道如何传递功能 \1

任何的想法?

python regex

0
推荐指数
1
解决办法
706
查看次数

如何在Python中执行comm Linux命令

我想从File1中提取File2中不存在的行

文件1

a  
b  
c  
Run Code Online (Sandbox Code Playgroud)

文件2

a  
c  
Run Code Online (Sandbox Code Playgroud)

所以输出应该是:

b  
Run Code Online (Sandbox Code Playgroud)

bash中的一个可能的命令是:

comm -23 <(sort File1) <(sort File2) > File  
Run Code Online (Sandbox Code Playgroud)

它在bash中运行得非常好,但我不知道在Python中如何正确实现.

我试过了

import os  
os.system("comm -23 <(sort File1) <(sort File2) > File")  
Run Code Online (Sandbox Code Playgroud)

并没有奏效.任何提示?

python linux bash

0
推荐指数
2
解决办法
579
查看次数

标签 统计

awk ×3

linux ×3

python ×3

sed ×3

regex ×2

bash ×1

emacs ×1

grep ×1

python-3.x ×1

replace ×1

thai ×1

tr ×1

unicode ×1