[英]Regex expression for removing pipe, spaces, parenthesis, but not quotes using python
Can someone help me out.有人可以帮我吗。 I want a Regex expression for removing pipe, spaces, parenthesis, but not quotes using python.
我想要一个正则表达式来删除管道、空格、括号,但不使用 python 删除引号。
Say I am taking my input as a json and I want the output like I mentioned below.假设我将我的输入作为 json 输入,并且我想要如下所述的输出。 Since my input has double quotes inside a double quotes and I want the words along with the quotes, I am confused.
由于我的输入在双引号内有双引号并且我想要单词和引号,所以我很困惑。
Sample Input:样本输入:
"Iam new to "Regular Expressions" | I (started) learning it "Recently""
Desired Output:期望输出:
Iam
new
to
"Regular Expressions"
I
started
learning
it
"Recently"
Regular expressions probably are too heavy a tool for that purpose.正则表达式对于这个目的来说可能太重了。 Instead,
str.replace
should be more than enough.相反,
str.replace
应该绰绰有余。
Small example:小例子:
>>> s = "'h|e l)l( o , w o)r(l|d'"
>>> s = s.replace(")", "")
>>> s = s.replace("(", "")
>>> s = s.replace(" ", "")
>>> s = s.replace("|", "")
>>> s
"'hello,world'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.