473,803 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Matching line with 3 or more repetitions of the same date

numberwhun
3,509 Recognized Expert Moderator Specialist
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:

Expand|Select|Wrap|Line Numbers
  1. if($line =~ m/(\d+\/\d+\/\d+\s*){2,}/)
  2. {
  3.     print("Line Number $. ==>  $line \n")
  4. }
  5.  
Can anyone please tell me how I can match this string format:

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

and not any other, whether there are two dates or a dozen or so?

Regards,

Jeff
Jul 25 '07
13 1387
numberwhun
3,509 Recognized Expert Moderator Specialist
I have said it before and I will say it again. I learn something new every day being a Perl coder, and I LOVE IT!!

Thanks again Miller!!

Regards,

Jeff
Jul 25 '07 #11
KevinADC
4,059 Recognized Expert Specialist
I didn't read the entire thread so I may have missed something, but this regexp looks like it need to use the string anchors ^$ to match the repeated date and only the repeated date from start to finish of the line:

Expand|Select|Wrap|Line Numbers
  1. if (m{^(\d{2}/\d{2}/\d{4})(?:\s*\1){2,}$}) {
otherwise it is only matching a sub string and a different date at the beginning or end will still return true .
Jul 26 '07 #12
miller
1,089 Recognized Expert Top Contributor
Yes, if you read the entire thread, you'll see that anchors are not desired. He only wishes to match a substring with the given properties.

- Miller
Jul 26 '07 #13
KevinADC
4,059 Recognized Expert Specialist
Yes, if you read the entire thread, you'll see that anchors are no desired. He only wishes to match a substring with the given properties.

- Miller
OK, gotcha. :)

......
Jul 26 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5495
by: | last post by:
Hi, I'm fairly new to regular expressions, and this may be a rather dumb question, but so far I haven't found the answer in any tutorial or reference yet... If I have f.i. the string "The {{{{power of {{{{regular expressions}}}} comes from}}}} the ability to include alternatives and repetitions in the pattern." from which I want to extract chunks starting with "{{{{" and ending with "}}}}".
3
1761
by: Greg Lindstrom | last post by:
Hello- I'm running Python 2.2.3 on Windows XP "Professional" and am reading a file wit 1 very long line of text (the line consists of multiple records with no cr/lf). What I would like to do is scan for the occurrence of a specific pattern of characters which I expect to repeat many times in the file. Suppose I want to search for "Start: mm/dd/yy" and capture the mm/dd/yyyy data for processing each time I find it. This is the type of...
17
14078
by: Andrew McLean | last post by:
I have a problem that is suspect isn't unusual and I'm looking to see if there is any code available to help. I've Googled without success. Basically, I have two databases containing lists of postal addresses and need to look for matching addresses in the two databases. More precisely, for each address in database A I want to find a single matching address in database B. I'm 90% of the way there, in the sense that I have a simplistic...
2
1766
by: brice | last post by:
Hello, I am using using the following code to transform a memo xml file. I am using Internet Explorer 6.0 to transform and view the file as HTML. <!-- ***** BEGIN XML ***** --> <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <MEMO ID="1"> <AUTHOR ID="1">
10
4985
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement, knowledge of fast and practical algorithms is not commonplace." Hume and Sunday, "Fast String Searching", Software - Practice and Experience, Vol. 21 # 11, pp 1221-48
2
4783
by: William | last post by:
The script below runs correctly in ASP but not ASPX. Im not sure why? Please help. Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30081: 'If' must end with a matching 'End If'. Source Error:
7
1704
by: matteosartori | last post by:
Hi all, I've spent all morning trying to work this one out: I've got the following string: <td>04/01/2006</td><td>Wednesday</td><td>&nbsp;</td><td>09:14</td><td>12:44</td><td>12:50</td><td>17:58</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>08:14</td> from which I'm attempting to extract the date, and the five times from into a list. Only the very last time is guaranteed to be there so it
7
3279
by: Kevin CH | last post by:
Hi, I'm currently running into a confusion on regex and hopefully you guys can clear it up for me. Suppose I have a regular expression (0|(1(01*0)*1))* and two test strings: 110_1011101_ and _101101_1. (The underscores are not part of the string. They are added to show that both string has a substring that matches the pattern.) Applying a match() function on the first string returns true while false for the second. The difference...
8
3911
by: 116Rohan | last post by:
I came across a question in one of the Computing olympiad regarding string pattern matching. Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator, that prints out the decimal representation. If the decimal representation has a repeating sequence of digits, it should be indicated by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as .(3), and 41/333 =...
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10550
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.