我正在寻找一个正则表达式,它可以从字符串中删除以下所有字符(以及空格): ~ % & \ ; : " ' , < > ? #。你能帮我吗?我正在使用ActionScript 3编码。
yourString.replace(/[~%&\\;:"',<>?#\s]/g,"");
$_ = "~ % & \\ ; : \" ' , < > ? #";
s/[~%&\\;:"',<>?#\s]//g;
print; #prints nothing
[~%&\\;:"',<>?#\s]+
$mystring
中删除所有空格,您需要添加其他字符以创建您的正则表达式。$mystring = "...";
$mystring =~ s/\s//g;
import re
with open ('txt.txt', 'r') as fi: # to read ur file
tm = fi.read().replace(',', '\n,') # to replace " , " with \n{enter} i.e to new line
with open ('out_3.txt','w') as z: # to crate new file wher all changes will done or we simply say that to write a new file
for j in tm:
y = re.sub("[0-9 {} <> -,: _\. = +| \/]",'\n' , j)# to remove required
正则表达式可以根据需要进行更改或修改,因为我没有将“?”作为正则表达式添加,但您可以添加如下--y = re.sub("[0-9 {} <> -,: _\.? = +| \/]",'\n' , j)
有关re.sub的更多详细信息,请阅读此文档https://docs.python.org/3.1/library/re.html
for gn in y:
z.write(gn)