Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regexp-matching character n times in the line.

Reply
Thread Tools

Regexp-matching character n times in the line.

 
 
Rodrigo A B Freire
Guest
Posts: n/a
 
      09-22-2004
Regexp gurus,

I'm trying to build a regular expression that matches a exact count of
a character.

I explain.

Analyzing my mail log, I noticed that *every* traffic with sender
addresses containing four underscores are spam. Examples:

http://www.velocityreviews.com/forums/(E-Mail Removed)
(E-Mail Removed)
(E-Mail Removed)

The regexp should match every email address containing 4 underscores.

Any idea?

Thank you,

Rod.
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-22-2004
"Rodrigo A B Freire" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> Regexp gurus,
>
> I'm trying to build a regular expression that matches a exact count of
> a character.
>
> I explain.
>
> Analyzing my mail log, I noticed that *every* traffic with sender
> addresses containing four underscores are spam. Examples:
>
> (E-Mail Removed)
> (E-Mail Removed)
> (E-Mail Removed)
>
> The regexp should match every email address containing 4 underscores.
>
> Any idea?


perldoc -q count
There are a number of ways, with varying efficiency.
If you want a count of a certain single character
(X) within a string, you can use the "tr///"
function like so:

$string = "ThisXlineXhasXsomeXx'sXinXit";
$count = ($string =~ tr/X//);
print "There are $count X characters in the string";

Paul Lalli


 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      09-22-2004


Rodrigo A B Freire wrote:

> I'm trying to build a regular expression that matches a exact count of
> a character.
>
> I explain.
>
> Analyzing my mail log, I noticed that *every* traffic with sender
> addresses containing four underscores are spam. Examples:
>
> (E-Mail Removed)
> (E-Mail Removed)
> (E-Mail Removed)
>
> The regexp should match every email address containing 4 underscores.


/^([^_]*_){4}[^_]*$/


 
Reply With Quote
 
Rodrigo A B Freire
Guest
Posts: n/a
 
      09-23-2004
Brian,

Worked like a charm! ;]

Thank you,
Rod.

Brian McCauley <(E-Mail Removed)> wrote in message news:<cisinv$h34$(E-Mail Removed)>...
> Rodrigo A B Freire wrote:
> > I'm trying to build a regular expression that matches a exact count of
> > a character.
> > I explain.
> > (E-Mail Removed)
> > (E-Mail Removed)
> > (E-Mail Removed)
> >
> > The regexp should match every email address containing 4 underscores.

>
> /^([^_]*_){4}[^_]*$/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When to use std::pow(x,n) instead of times x for n times? Peng Yu C++ 17 09-14-2008 04:10 PM
Forms Authentication Fails some times and not some times??? =?Utf-8?B?bWF2cmlja18xMDE=?= ASP .Net 0 03-28-2006 10:48 PM
SetAuthCookie works some times and fails some times? =?Utf-8?B?bWF2cmlja18xMDE=?= ASP .Net 0 03-23-2006 09:24 PM
Boot Times and Recycle Times Moo Digital Photography 3 11-20-2004 12:31 PM
Why is the Constructor called 4 times but the Destructor 5 times? djskrill C++ 9 10-01-2003 07:18 PM



Advertisments