Regular Expression to find repeating pattern?

Can a Regular Expression find and return any repeating pattern, where
you don't know what the repeating pattern will be?

For example, given the strings:
   abababab
   abcdeabcdeabcde

Can a Regular Expression find that (a) these strings have repeating
patterns, and that (b) the patterns are ab for the first string, and
abcde for the second string?

I realize it's easy to find a repeating pattern if you know the exact
pattern you're looking for. What I'm asking about is where you don't
know what the repeating pattern might be, nor how many characters it
might be.


Thanks,

Greg
0
Greg
12/3/2009 9:37:08 PM
scripting.vbscript 564 articles. 0 followers. Follow

1 Replies
3135 Views

Similar Articles

[PageSpeed] 3

On Dec 3, 10:37=A0pm, Greg Lovern <gr...@gregl.net> wrote:
> Can a Regular Expression find and return any repeating pattern, where
> you don't know what the repeating pattern will be?
>
> For example, given the strings:
> =A0 =A0abababab
> =A0 =A0abcdeabcdeabcde

Dim str: str =3D "abababababab"
Dim re: Set re =3D new RegExp
re.pattern =3D "^(.*?)\1+$"
Dim aM: Set aM =3D re.Execute(str)
If aM.count Then MsgBox aM.item(0).SubMatches(0) _
            Else MsgBox "Non repetitive string"


Note that what you are looking for is ambiguous in the above
case, as str is a repetition of ab, abab, AND ababab.
The regular expression that I have gives the smallest
substring of which the test string is a repetition.  To find the
longest string of which the test string is a repetition of, lose
the question mark:
ie: ^(.*?)\1+$  (shortest)  vs.  ^(.*)\1+$  (longest)

Csaba Gabor from Vienna
PS.  It's always nice to hear a liitle background to
where the problem is coming from.
0
Csaba
12/3/2009 10:47:09 PM
Reply:

Similar Artilces:

Find and replace 03-04-10
I'm trying to scan a field in one of my tables and find a specific character and remove it. However, the character is a " so I'm having difficulty. The field I speak of of contains the sizes of our material so the values look like this: 1/4" 1/2" 1/3" and so on. How can I find all of the " in my feild and remove them? I don't want to replace them I just want to remove them. Thanks, Chris Savedge Create a query, and in the Criteria row under the problem field, enter: Like "*[""]*" -- Allen Browne - ...

How can I find career change resumes templates?
I like to review some nice "Professional Career Change Resume Templates" for the job market. If someone could tell me where to go on the inter-net, it will be well appreciated. Thanks! You could start at www.google.com "Mike" <Mike@discussions.microsoft.com> wrote in message news:705F99E5-1326-4E81-B98F-A7337C5C9AEA@microsoft.com... :I like to review some nice "Professional Career Change Resume Templates" for : the job market. If someone could tell me where to go on the inter-net, it : will be well appreciated. Thanks! Templates are...

Lookup/Find help
Windows XP Professional Office 2000 Hypothetical, but hopefully you'll get the gist of it: I have two worksheets. On worksheet #1, I have two columns. First column is a list of entire workgroup by name and 2nd column is the hours worked. On the second worksheet I simply have an list of names that is a subgroup of those on the first page. These indicate a target group. EXAMPLE Worksheet #1 Sam 35 Joe 37 Mary 20 Beth 41 Ted 38 Worksheet #2 Joe Beth Now, on the first worksheet, I want to add a third column for summing only the target workgroup. Basically, I need a function...

Outlook Express 6 #54
When I am in Newsgroups and havee aa lot of items and want to close them, OE will ofton "hang" when I click "mark aall read". This throws me out of Outlook and onto my desktop. Using Media Center Edition 2005 XP. Does anyone else experience this? TIA Donald Sessler <sloopokespam@opto.net> wrote: > When I am in Newsgroups and havee aa lot of items and want to close > them, OE will ofton "hang" when I click "mark aall read". This throws > me out of Outlook and onto my desktop. Using Media Center Edition > 2005 XP. Does anyone else...

Outlook Express BCC options
Is there anyway to set Outlook Express to send email to multiple addresses ONLY BCC? I want to completly eliminate the option to CC. Thank you in advance! Christine ...

Adding functionality to MS Outlook Express
Hi, I am looking for help to integrate anti-spam open source programs with MS Outlook Express :- - SpamPal - http://www.spampal.org/ - Spamato - http://www.spamato.net/ The problem is to provide a library that will facilitate this. I have read the MSDN Messaging and Collaboration documentation which gives the ability to get notifications of new messages and to access message folders :- http://msdn2.microsoft.com/en-gb/library/ms709546.aspx The next need is to add a toolbar (with buttons for SPAM/NOSPAM) and to detect what messages are selected in the message window. The MSOE...

can't find normal.dot
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC Hello, I need to delete my normal.dot file and I can't find it anywhere. I've had to do this before and I was able to find it in the templates folder, but I guess an update or two has changed that. Can anyone tell me where to find it? Spotlight says that it doesn't exist. But I have to be able to delete it. Is it called something different now? If you're using Spotlight & searching for "Normal.dot" it's no wonder it isn't being found - that isn't the correct name :-) it's ...

Finding maximum value
Hello, I want to find the maximum value in a column, but I want to ignore the negative and positive part of the value. Basically, the maximum difference from zero. Example: the maximum value I am looking for will be -0.467. -0.467 0.345 -0.253 0.411 Thanks Ruan One way (array-entered: CTRL-SHIFT-ENTER or CMD-RETURN): =INDEX(A1:A4,MATCH(MAX(ABS(A1:A4)),ABS(A1:A4),FALSE)) In article <OGKhnF1KEHA.2100@TK2MSFTNGP10.phx.gbl>, "Ruan" <ruan@aegismed.com> wrote: > Hello, > > I want to find the maximum value in a column, but I want to ignore the > negati...

How do I find the inside page in the 3-panel brochure.
I am trying to make a 3-panel brochure and all that seems to be available is the side shown in the brochure options. When I print, it prints both sides yet I can see no way to access the inside part. Thanks. View, status bar... this will allow you to change page views, you will see the page tabs at the bottom of the screen. I am not sure I know what you are asking. Are you saying you are printing the brochure sight unseen? -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "springmtn" <springmtn@discussions.microsoft.co...

Find a multiple photos on a page template for Publisher?
Possible to find a template for Publisher to print a page full of multiple photos without recreating the page each time I print. Why not save your page you have created as a template? File, "save as", files of type, scroll down to Publisher template. -- Mary Sauer http://msauer.mvps.org/ "srfaith" <srfaith@discussions.microsoft.com> wrote in message news:157E95AB-1159-4889-B196-61E147E6E240@microsoft.com... > Possible to find a template for Publisher to print a page full of multiple > photos without recreating the page each time I print. ...

How do you control the color/pattern of a pie chart?
I need help with my pie charts. I need to create pie charts that are easily understood in B&W. How do I set the color or pattern for each portion of my pie chart? Hi, To format a slice you need to select it first. Click the pie once to select all slices. Click again to select individual slice. You can use the Fill Effects > Patterns to fill with b/w patterns. Also in print preview the Setup dialog has a Print Black & White option on the Chart Tab. Note this is only visible if you have a chart sheet or select the chartobject before print preview. If you are printing chartobje...

Finding Desktop region in MFC
I am working on a commercial application, and recently discovered a bug I have been asked to fix (they threw it back in my lap). Run the application on a 2-monitor system, such as a laptop in a dock with an external monitor. Drag the main window to the second (non-taskbar) window and quit. Now move the laptop to a different dock with the second menu on the other side (or without a second monitor at all) and launch the app. Oops. The app continues to want to go on the side it was last put, even though there is now no monitor there. (Yes, my dock in the office and at home have the second ...

Performance counter for Outlook Finds?
What server performance counters (if any) are there for monitoring the number of "Find" requests that Outlook clients make? -GT ...

finding calendar and data info
I had to move my primary hard drive into another computer. It is now running as a slavein the new computer. I'm unable however, to find my calendar and contacts from Outlook 2003 when I open the program on the new computer. If I attempt to open the program from the F drive (the drive assigned in the new computer to the hard drive that was moved from another computer) it tells me the program is not installed. If I open Outlook 2003 from the C drive of the new computer, of course, it doesn't find the old calendar and contacts. I would appreciate any and all assistance in findin...

Conditional Formatting VBA with formula to find string
Hi, Please can I get some help.... I need to create a conditional format VBA in Excel 2007 (because I have many conditions to include) and I don't know how to do it... The Action Required: If Product A appears in any text string in range($C$95:$C$300) then colour that cell RED, if Product B appears anywhere in a text string within range($C$95:$C$300) then colour that cell BLUE, if Product B appears anywhere in a text string within range($C$95:$C$300) then colour that cell GREEN, and so on through 41 products... Data - I have a list of about 41 Product names in range Z...

Using sdk to find out if an Account already exists
Hi, Want to use sdk to see if an Account already exists , all i have is its name. I've looked at Retrieve method but it requires the Guid. Any equivalent call to Retrieve that just takes name? Or a way to get the Guid from the name? Sample code would be great if available. Thanks for all help. John Hi John, The method you are looking for is RetrieveMultiple as only the guid search gives the certainty to retrieve only one record. All explanations are in the sdk but as the sdk sample is nearly the exact code you want, here it is : // Set up the CRM Service. CrmService service =3D new ...

Find number of weekdays and wekend days given a total number of da
Hello, I have a question for the gurus here. I am working on a spreadsheet where in column A I have Total # of Vacation days. Example: # Vac Days --- # Weekdays --- # Weekend days 75 55 20 44 32 12 25 19 6 I figured this out by simply creating a list like this 1 Weekday 2 Weekday 3 Weekday 4 Weekday 5 Weekday 6 Weekend 7 Weekend And so on... And then doing a countif to figure out how many of either on...

Doesn't find files w/spaces in name
There are a lot of folders and Excel spreadsheets on our shared drive that I need to open. Most of the folders and file names are named like: get reports\reports sep 2004.xls When I try to open one, Excel doesn't find it and I think it's because there are spaces in the folder names and/or file names. Is there a setting in Excel that will help me get around this? This was working until I had a glitch in Excel and the technician fixed the glitch and this problem appeared. Any help would be appreciated. I found an answer and so far it works. "C:/program files/microsoft off...

SQL statement to find a particular column within all tables
I am looking for a query that will allow me to find all instances of a particular column within all tables so I know where they are all located. Does anyone have such a query they would be willing to share? Thank you. Pam, I posted this query a few months aback on my blog (http://dynamicsgpblogster.blogspot.com/2008/03/in-past-days-i-have-found-lot-of-people.html), but here is the excerpt: select distinct rtrim(objs.name) from syscolumns cols inner join sysobjects objs on (cols.id = objs.id) inner join sysindexes indx on (cols.id = indx.id) where (cols.name = 'ACTINDX') and (ob...

outlook express 6 to outlook express 2000
how do I transfer my address book from one computer running outlook express 6 to my new computer running outlook express 2000. Thanks Bob There is no such Outlook Express version as 2000...did you mean Outlook 2000, or did you mean some other version of OE? -- Jocelyn Fiorello MVP - Outlook *** Replies sent to my e-mail address will probably not be answered -- please reply only to the newsgroup to preserve the message thread. *** "Bob" <brubaker@bendcable.com> wrote in message news:05b501c34a6e$da07fb40$a301280a@phx.gbl... > how do I transfer my address book from o...

find
How can I setup a macro or use a function to find a column who's first cell is called "Addresses" then move the whole column to sheet 2. Is it possible? Puzzled J, If there is only one cell with the word "Addresses" in it: Sub MoveAddresses() Cells.Find("Addresses").EntireColumn.Cut Worksheets("Sheet 2").Range("IV1").End(xlToLeft)(1,2) End Sub This will put the column into the column with the first free cell in row 1 of Sheet 2. HTH, Bernie MS Excel MVP "J Bates" <newss@pittam.plus.com> wrote in message news:4507...

How to change the default font size for outlook express?
I would like change default font size for outlook express? the default font size is 10, and I prefer 12 as default. Does anyone have any suggestions? Thanks in advance for any suggestions Eric Tools | Options | Compose. -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Eric" <Eric@discussions.microsoft.com> wrote in message news:975D75C0-1CA0-4325-A9D6-EC7510AFA86C@microsoft.com... >I would like change default font size for outlook express? the default >font > size is 10, and I prefer 12 as default. > Does anyone hav...

Moving SQL Express Database
Hey, We have a client on 3.0 with a user that switched machines while in offline mode. They installed the Laptop client on the new machine and now they need to move the SQL Express db from the old machine to the new one. How can we make this happen? Is there a database file we can copy and move to the new machine?? Any help would be great... ...

XP Outlook Express
Could not save or open attachments. Have the message on top "OE removed access to the following unsafe attachments in your mail". The "Save attachments" was also disabled underneath the Attachment icon. I have downloaded all the window updates for Outlook Express and Internet Explorer but this problem still peristed. Because it is not a problem but a configuration setting. Tools-> Options-> option Do not allow... Note that this is an Microsoft Office Outlook forum. Outlook Express is family of Internet Explorer and Outlook of the Office family. Here is the ...

Finding/deleting macros...
Thanks to anyone who helped me with my finding/deleting link question... Now in a different workbook.. when i open it, it prompts whether t enable or disable macros. When i go to the macros list though, it blank, none listed. How could I find where thesee phantom macros ar and get rid of them? FYI we always choose Disable macros. This is work book that was built a long time ago, probably has about 50+ tab of which we only currently use about 15. Thanks for any help! Chri -- Message posted from http://www.ExcelForum.com Hi you also have to remove the modules: - open the VBA editor (hi...