匹配线与同一日期的3次或更多次重复 [英] Matching line with 3 or more repetitions of the same date

查看:46
本文介绍了匹配线与同一日期的3次或更多次重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好!


我有一个数据文件,其中包含每行的杂项信息。 (不幸的是,我不能详细介绍文件布局,因为它是敏感信息),但我可以说每行都是多个位置的日期。一行中的某些区域包含多个日期,因为字段之间没有分隔(即:没有空格):


ie:05/26/200706/03 / 200707/24/2007


如您所见,上面有3个日期。有些字段彼此跟随,如上所述,日期之间只有至少一个或多个空格:


ie:05/26/2007 06/03/2007 07 / 24/2007


这是一个有点毛茸茸的地方。在某些文件中,有一个任意的日期字符串。日期字符串如下所示:


ie:07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007 07 / 24/2007


可能有2个,5个,7个或更多日期,所有日期都串在一起,但它们在该行的字符串中的日期相同。


我正在尝试编写一个匹配这个相同日期的任意字符串的正则表达式,但不幸的是,它匹配任意多个日期的字符串。这是我到目前为止:

Hello everyone!

I have a data file that contains miscellaneous information on each line. (Unfortunately, I cannot go into detail of the file layout as it is sensitive information), but I can say that on each line are dates in multiple positions. Some areas of a line contain multiple dates, strung together because there is no separation between the fields (ie: no space(s)):

ie: 05/26/200706/03/200707/24/2007

As you can see, there are 3 dates above. Some have fields following each other that are as above, only there is at least one or more spaces between the dates:

ie: 05/26/2007 06/03/2007 07/24/2007

This is where it gets a little hairy. In some files, there is an arbitrary string of dates. The string of dates would look as follows:

ie: 07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007

There may be 2, 5, 7, or more dates, all strung together, but they are all the same date through the string on that line.

I am trying to write a regex that will match this arbitrarty string of identical dates, but unfortunately, it matches any string of multiple dates. Here is what I have so far:

展开 | 选择 | Wrap | 行号

推荐答案

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号


Miller,


WOW !!我整天都在这,我的大脑疼痛。谢谢!谢谢!


现在,你有没有机会告诉我那个正则表达式的哪一部分说日期必须相同?


问候,


杰夫
Miller,

WOW!! I have been at this all day and my brain is sore. Thank you! Thank you!

Now, any chance of you telling me which part of that regex says that the dates have to be identical?

Regards,

Jeff


好的,针对我快速组合的一些数据运行这个,我认为可能还有问题。


日期并不是每条线上唯一的东西。日期之前和之后都有文字。他们只是一些领域。我说字段作为被检查的文件有点像平面文件数据库,其中每一行都是一个记录。


我刚刚遇到的测试数据是:


###开始数据###


这是一行文字。

这是另一行文字。

这是第二行文字。 07/24/2007 07/24/2007 07/24/2007 07/24/2007

07/24/2007 07/24/2007 07/24/2007 07/24/2007

这是第五行。

07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007


###结束数据###


现在,当我对此运行正则表达式时,它打印出来:


第6行==>
问题是,打印的数据来自第4行。


问候,


Jeff
Ok, ran this against some data I put together really quickly and I think there may still be an issue.

The dates aren''t the only thing on each line. There is text before and after the dates. They are just some of the fields. I say fields as the file being examined is kind of like a flat file db where each line is a record.

The test data I just ran against is:

### Begin data###

This is a line of text.
This is another line of text.
This is the thirs line of text. 07/24/2007 07/24/2007 07/24/2007 07/24/2007
07/24/2007 07/24/2007 07/24/2007 07/24/2007
This is the fifth line.
07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007 07/24/2007

### End Data ###

Now, when I ran the regex against this, it printed:

Line Number 6 ==> 07/24/2007 07/24/2007 07/24/2007 07/24/2007

Problem is, the data printed is from line #4.

Regards,

Jeff


这篇关于匹配线与同一日期的3次或更多次重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆