簡體   English   中英

刪除pyhton中2個單詞之間的文本和所有換行符

[英]delete text and all new line characters between 2 words in pyhton

我有以下文字

\nOUTPUTFORMAT \n  
\'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat\'\nLOCATION\n  
\'hdfs://nameservice1/user/hive/warehouse/dev_cmt.db/badge\'\nTBLPROPERTIES (\n  
\'spark.sql.create.version\'=\'2.4.0-cdh6.3.2\', \n  
\'spark.sql.sources.schema.numPartCols\'=\'1\', \n  \'spark.sql.sources.schema.numParts\'=\'1\'

我想刪除從 LOCATION 到 TBLPROPERTIES 開頭的所有內容。 我正在嘗試使用正則表達式,但到目前為止我一直沒有成功。

\nOUTPUTFORMAT \n  
\'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat\'\nTBLPROPERTIES (\n  
\'spark.sql.create.version\'=\'2.4.0-cdh6.3.2\', \n  
\'spark.sql.sources.schema.numPartCols\'=\'1\', \n  
\'spark.sql.sources.schema.numParts\'=\'1\'

提前感謝您的建議。

import re
text = "\nOUTPUTFORMAT \n\'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat\'\nLOCATION\n\'hdfs://nameservice1/user/hive/warehouse/dev_cmt.db/badge\'\nTBLPROPERTIES (\n\'spark.sql.create.version\'=\'2.4.0-cdh6.3.2\', \n\'spark.sql.sources.schema.numPartCols\'=\'1\', \n\'spark.sql.sources.schema.numParts\'=\'1\'"
text = re.sub(r'LOCATION.*TBLPROPERTIES', 'TBLPROPERTIES', text, flags=re.DOTALL)
print(text)

看看這是否有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM