How to do this job with regular expression

N

news.hinet.net

$a=~/\s{10,}?/

It can find that $a match spaces at least 10 times.

but how to find that if $a have the same word at last 4 times.
like. 666666 222222 11111 aaaaa bbbb
 
B

Brian McCauley

news.hinet.net wrote:

[ Unless you really are the Usenet admin for Hinet you should change
your missleading "From" header ].
$a=~/\s{10,}?/

Note: At the end of a regex {10,}? ("as few as possible but at least 10
times") is the same as simply {10} ("exactly 10 time")
It can find that $a match spaces at least 10 times.

but how to find that if $a have the same word at last 4 times.

By 'word' I shall assume you meant to say 'word character'.

/(\w)\1{9}/

I'm fairly sure this is a FAQ but I don't seem to be able to find it in
the list.
 
J

Josef Moellers

news.hinet.net said:
$a=~/\s{10,}?/

It can find that $a match spaces at least 10 times.

but how to find that if $a have the same word at last 4 times.
like. 666666 222222 11111 aaaaa bbbb

You probably mean "letter" rather than "word", as there are no two
identical words in that line.

The keyword you are looking for is "backreference", e.g.
$a =~ /(.)\1\1\1/;
matches 4 identical anythings in $a.
You can put more complex patterns between the parentheses if you desire.
 

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,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top