Match repeating pattern

S

Serman D.

$ perl -wle 'print 1/7'
0.142857142857143

How do I match the a repeating pattern within a string? Of the above
string I want to match '142857'.

Thanks.

Serman D.
--
 
U

usenet

How do I match the a repeating pattern within a string? Of the above
string I want to match '142857'.

Please clarify: What if the string is 0.2323232323232323

Would you want to match 23? or 2323? or 232323? Or 232232323?

All of these patterns are repeated in the string.

If the string is: 0.111A111B111

Would you expect to match 111? (ie, matches not sequential)
 
T

Tad McClellan

Serman D. said:
$ perl -wle 'print 1/7'
0.142857142857143

How do I match the a repeating pattern within a string? Of the above
string I want to match '142857'.


perl -le 'print $1 if (1/7) =~ /\.(\d+)\1+/'
 
T

Tad McClellan

Serman D. said:
I want to match the longest, sequential repeating pattern within the
string.


What if the string is 12341234.567567 ?

perl -le 'print $1 if "12341234.567567" =~ /(\d+)\1+/'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,674
Latest member
scazeho

Latest Threads

Top