删除所有其他换行符

删除所有其他换行符

本文介绍了删除所有其他换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本格式的数据列表,如下所示:


Name1 Name2


$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b
Name1 Name2



位置工作日期金额
$ / code
$ b $ p $ Name $ Name2





$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'



我需要以某种方式进入



Name1 Name2 location工作日期金额



...



必须用正则表达式或者Excel来抓住每一个换行符。我可以写一个python脚本,但是这个文件是一个痛苦,希望有一个更简单的方法来做到这一点。

编辑:添加我在下面试过的内容:

对不起,我应该包含一些代码。 。我试过

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

在正则表达式中,但是把这两行组合在一起,我基本上只想抓住组。我也试着在excel中系统地做这件事,但是当我拖动盒子的时候,它不会继续抓住每一个单元格。它会从列中的每一个单元格改变到每个单元格,一旦我尝试挤压它。 使用.Net正则表达式调味(应该是VBA相同,但我没有检查),我想出了以下内容:

  Pattern =( [^ \\\
] *)(\\\
)([^ \\\
] *(\\\
| \z))
Replacement =$ 1 $ 3

基本上,捕获第二个捕获组中的第一个NewLine字符,然后在我们的替换中不返回。



希望这有助于。


I have a list of data in text format that looks as follows

Name1 Name2

location job date amount

Name1 Name2

location job date amount

Name1 Name2

location job date amount

I need to somehow make this into

Name1 Name2 location job date amount

...

I figure there has got to be a way to grab every other newline with either regex or excel. I could write a python script but this file has been a pain and was hoping there would be an easier way to do it.

EDIT: adding what I've tried below:

Sorry, I should have included some code... I tried

([^\n]*\n)[^\n]*\n

in regex, but that groups the two lines together, I basically would like to grab only the newline between the groups. I have also tried doing this in excel systematically but it doesn't continue to grab every other cell when I drag the box down. It changes from every other cell in the column to every cell once I try to extrude it.

解决方案

Using .Net regex flavoring (should be the same for VBA, but I didn't check), I came up with the following:

Pattern = "([^\n]*)(\n)([^\n]*(\n|\z))"
Replacement = "$1$3"

Basically, catching the first NewLine character in the second capture group and then not returning it in our replacement.

Hope this helps.

这篇关于删除所有其他换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:15