Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式删除python中多余的反斜杠_Python_Regex_Nlp - Fatal编程技术网

正则表达式删除python中多余的反斜杠

正则表达式删除python中多余的反斜杠,python,regex,nlp,Python,Regex,Nlp,我在列表中列出了以下文本: text='More Fulham接受史蒂芬·约翰森、让·迈克尔·塞里和马克西姆·勒马尔坎德的报价QPR热衷于富勒姆的史蒂芬·约翰森,他本赛季没有入选斯科特·帕克的英超阵容;加拉塔萨雷希望让·迈克尔·塞里能够租借回来,而马克西姆·勒·马尔坎德正在吸引前俱乐部尼斯·费勒2的兴趣,副本11,2021年1月20日星期三16:51,英国图片:皇后公园游骑兵队有兴趣签下斯蒂芬·约翰森\\n福勒姆正在听取斯蒂芬·约翰森的报价,马克西姆·勒马尔坎德和让·迈克尔·塞里在一月份转会窗口

我在列表中列出了以下文本:

text='More Fulham接受史蒂芬·约翰森、让·迈克尔·塞里和马克西姆·勒马尔坎德的报价QPR热衷于富勒姆的史蒂芬·约翰森,他本赛季没有入选斯科特·帕克的英超阵容;加拉塔萨雷希望让·迈克尔·塞里能够租借回来,而马克西姆·勒·马尔坎德正在吸引前俱乐部尼斯·费勒2的兴趣,副本11,2021年1月20日星期三16:51,英国图片:皇后公园游骑兵队有兴趣签下斯蒂芬·约翰森\\n福勒姆正在听取斯蒂芬·约翰森的报价,马克西姆·勒马尔坎德和让·迈克尔·塞里在一月份转会窗口期间。\\n公园流浪者队有兴趣签下富勒姆中场约翰森。这位挪威国脚在本赛季上半段没有入选斯科特·帕克的英超阵容。\\n 30岁的恩霍汉森自2016年从凯尔特人加盟以来,已经为俱乐部出场142次,他与克拉文别墅的合同有效期至2022年。帕克:我不欠穆里尼奥一个道歉\\这位中场球员在2018/19赛季的下半段租借到西布罗姆,但在下个赛季之前就回来了,在冠军联赛中踢了33场比赛,富勒姆通过季后赛获得了晋级。图片:让·迈克尔·塞里上个赛季被租借到加拉塔萨雷\\n富勒姆和加拉塔萨雷之间关于租借中场让·迈克尔·塞里的可能性的讨论仍在继续。趋势最新消息\\n这名29岁的中场球员将第二次以租借的形式加盟土耳其俱乐部,上赛季在那里的时候,塞里已经为超级Lig效力了37次。\\n塞里的合同将于2022年夏天到期,他可以选择将合同再延长一年。另请参见:图片:马克西姆·勒·马尔坎德上赛季为富勒姆出场12次,但本赛季迄今为止在斯科特·帕克手下只出场两次\\n而,法甲俱乐部尼斯希望后卫马克西姆·勒·马钱德回到安联里维埃拉。\\n 2018年7月,富勒姆从法国球队签下了勒·马钱德,而这位中后卫本赛季迄今为止仅两次在顶级联赛中亮相。\\n勒·马钱德目前与富勒姆的合同还有一年半的时间。\\n富勒姆,谁在本月底前在英超联赛中排名第18,离安全点还有4分,分别与曼联(1月20日)、伯恩利(1月24日)、布莱顿(1月27日)和西布罗姆(1月30日)进行足总杯比赛。\\n根据天空体育一月份的转会窗口\\冬季转会窗口开放至周一,2月1日晚上11点。\\n关注天空体育新闻和跨天空体育“数字平台”的所有新闻和分析,包括我们专门的换乘中心博客

并使用以下正则表达式预期删除\:

re.sub(r'\\\\\'',"\\'",text))
然而,输出正在清理额外的数据\


例如,文本有{don\\'t},使用下面的正则表达式,我打算将其转换为don't

,您可以使用replace方法。如果您只想删除“\”,则无需使用正则表达式 显然,您需要删除'\n'、'\t'等,然后可以使用它删除额外的'\'

text = text.replace('\\','')

奇怪的是,我15分钟前才查到这个。我尝试了几次你的文字,发现了一些有用的东西

首先,使用
repr(text)
将显示实际使用的反斜杠。此时将
\\\\\
替换为
\\\
,将生成正确的字符串,就像它是用Python编写的一样。它基本上相当于
“'+text+'”
,但就潜在的未替换语音标记而言更安全一些

从这里开始,
eval
将实际将其作为字符串处理

result = eval(repr(text).replace('\\\\', '\\'))
然后打印结果时,得到的结果如下:

More Fulham open to offers for Stefan Johansen, Jean Michael Seri and Maxime Le Marchand QPR are keen on Fulham's Stefan Johansen who was not included in Scott Parker's Premier League squad this season; Galatasaray want Jean Michael Seri back on loan while Maxime Le Marchand is attracting interest from former club Nice Fill 2 Copy 11 Wednesday 20 January 2021 16:51, UK Image: Queens Park Rangers are interested in signing Stefan Johansen
Fulham are listening to offers for Stefan Johansen, Maxime Le Marchand and Jean Michael Seri during the January transfer window.
Queens Park Rangers are interested in signing Fulham midfielder Johansen. The Norwegian international was not included in Scott Parker's Premier League squad for the first half of this season.
Johansen, 30, has made 142 appearances for the club since arriving from Celtic in 2016, he is under contract at Craven Cottage until 2022. Parker: I don't owe Mourinho an apology
The midfielder spent the second half of the 2018/19 campaign on loan at West Brom but returned ahead of the following season and played 33 times in the Championship as Fulham won promotion back to the Premier League via the play-offs. Image: Jean Michael Seri spent last season on loan at Galatasaray
Talks continue between Fulham and Galatasaray over the possibility of a loan deal for midfielder Jean Michael Seri. Trending Latest News
A move would see the 29-year-old central midfielder join the Turkish club on loan for a second time, with Seri having played 37 times for the Super Lig side while he was there last season.
Seri's contract expires in the summer of 2022, he has the option to extend the deal by a further year. Also See: Image: Maxime Le Marchand played 12 times for Fulham last season but has made just two appearances under Scott Parker so far this term
Meanwhile, Ligue 1 club Nice want defender Maxime Le Marchand to return to the Allianz Riviera.
Fulham signed Le Marchand from the French side in July 2018 and the centre-back has featured just twice in the top flight so far this season.
Le Marchand also has a year and a half remaining on his current contract at Fulham.
Fulham, who are 18th and four points from safety in the Premier League, play Manchester United (January 20), Burnley in the FA Cup (January 24), Brighton (January 27), and West Brom (January 30) before the end of the month.
Follow the January transfer window with Sky Sports
The winter transfer window is open until Monday, February 1 at 11pm.
Follow all the news and analysis on Sky Sports News and across Sky Sports ' digital platforms, including our dedicated Transfer Centre blog

请编辑您的问题,使示例变小,并在开头和结尾使用3个反勾`将其显示为代码。